Distributive-Network / PythonMonkey

A Mozilla SpiderMonkey JavaScript engine embedded into the Python VM, using the Python engine to provide the JS host environment.
https://pythonmonkey.io
Other
854 stars 40 forks source link

JS Assert - How to See in Python #358

Closed den-run-ai closed 5 months ago

den-run-ai commented 5 months ago

Describe your feature request here.

How can I catch console.assert condition failure in Python?

Code example

No response

philippedistributive commented 5 months ago

Hi, if you run the following minimal example it will print the assertion failure to the console:

import pythonmonkey as pm pm.eval('console.assert(false)') Assertion failed

den-run-ai commented 5 months ago

This makes it difficult to catch/handle on Python side, when only printed to the console.

On Wed, Jun 5, 2024 at 8:12 AM philippedistributive < @.***> wrote:

Hi, if you run the following minimal example it will print the assertion failure to the console:

import pythonmonkey as pm pm.eval('console.assert(false)') Assertion failed

— Reply to this email directly, view it on GitHub https://github.com/Distributive-Network/PythonMonkey/issues/358#issuecomment-2150322231, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4BTZODBP3WSOTIAH4B5JTZF4TGJAVCNFSM6AAAAABIZP4AXKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJQGMZDEMRTGE . You are receiving this because you authored the thread.Message ID: @.***>

philippedistributive commented 5 months ago

If you look at the specs for assert: https://developer.mozilla.org/en-US/docs/Web/API/console/assert_static printing to the console is all the assert method does

Perhaps you mean to use console.trace? https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static That should print according to specs as well...

philippedistributive commented 5 months ago

Please see https://github.com/Distributive-Network/PythonMonkey/pull/360 for a yet-unreleased fix to console.trace