Skip to content

Errors hidden when invoking Pyscript from native code #801

@dmamelin

Description

@dmamelin

I’ve been noticing odd issues when using native calls for a while, but now I have a simple reproducer:

@pyscript_compile
def test_native(log):
    async def native(callback):
        log("native start")
        res = await callback()
        log(f"native callback result {res}")
        return res

    return native

def callback_func():
    res = 0 / 0
   return res

def test_exception():
    log.info("start")
    try:
        test_native(log.info)(callback_func)
        log.info("no exception")
    except Exception as e:
        log.info(f"got exception {e}")
    log.info("end")

@time_trigger("once(now+3s)")
def start():
    log.info("start time_trigger")
    test_exception()
    log.info("stop time_trigger")

test_exception()

Output:

start
native start
native callback result None <-----
got exception division by zero
end
#3 sec
start time_trigger
start
native start
native callback result None <-----
no exception
end
stop time_trigger

With a direct call, the exception is raised, but note line native callback result None - it shouldn’t be there.
When called via a trigger - the exception is swallowed complete

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions