10000 Can't disable stderr DOM redirection · Issue #2220 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

Can't disable stderr DOM redirection #2220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
freakboy3742 opened this issue Oct 12, 2024 · 15 comments · Fixed by #2226 or #2229
Closed
3 tasks done

Can't disable stderr DOM redirection #2220

freakboy3742 opened this issue Oct 12, 2024 · 15 comments · Fixed by #2226 or #2229
Labels
needs-triage Issue needs triage type: bug Something isn't working

Comments

@freakboy3742
Copy link
Contributor

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a solution or duplication
  • I already searched in Google and didn't find any good information or help

What happened?

In the version of PyScript served by latest/pyscript.net, both stdout and stderr content is sent to the Javascript console.

In releases/2024.10.1/core.js, stdout and stderr is sent to the Javascript console - but stderr content is also sent to the DOM as red text in a pink box.

This appears to be the expected default behaviour; however, there doesn't appear to be a way to turn this behavior off. I've seen several references to an error plugin in older versions of the docs, along with instructions for how to disable that plugin; but the 2024.10.1 docs don't seem to mention this plugin or disabling it. It's not even clear if the plugins configuration item is even supported any more - the plugins page doesn't make any mention of the pyscript.toml configuration item that previously existed.

Making matters worse; the default stderr error handling on Micropython doesn't output text, but the ASCII values of any content printed to stderr, as one integer value per line (i.e., print("This is an error", file=stderr) generates a 16 DOM boxes containing "84", "104", "105", "115", "32", ...)

What browsers are you seeing the problem on? (if applicable)

Chrome, Safari

Console info

No response

Additional Context

Reproduction case: https://gist.github.com/freakboy3742/ed3073fcffd6d92bb374bcf85301f320

I discovered this in the context of BeeWare; Toga invokes warnings.warn() for some unimplemented features, which outputs to stderr by default. Third party libraries also frequently raise warnings as part of a migration process. Having those warnings surface on the DOM is undesirable from our perspective.

@freakboy3742 freakboy3742 added type: bug Something isn't working needs-triage Issue needs triage labels Oct 12, 2024
@WebReflection
Copy link
Contributor
WebReflection commented Oct 16, 2024

just FYI py-config doesn't pollute mpy environment/interpreter ... you need an mpy-config there due extremely different nature of the two environments (a reason for attribute config to be preferred in general).

I am not sure that final mpy script in your example is meant to ignore the config, and I've already fixed the underlying issue locally, but if that was the case, it should have a config explicit attribute too to confirm stuff works as expected in there too.

8000

@WebReflection
Copy link
Contributor

The MR version has been published as https://cdn.jsdelivr.net/npm/@pyscript/core@0.6.7/dist/core.js and its counter CSS part https://cdn.jsdelivr.net/npm/@pyscript/core@0.6.7/dist/core.css ... if you could test that already as working for your needs it'd be wonderful 🙏

@freakboy3742
Copy link
Contributor Author

The Pyodide backend now works as expected with those changes.

The Micropython backend also correctly outputs text, rather than ASCII codes when writing to the DOM.

However, under Safari (17.6, under macOS 14.7), when I use a mpy-config definition:

  <mpy-config>
      plugins = ["!error"]
  </mpy-config>
  <script type="mpy">
    import sys
    print("This is normal micropython content")
    print("This is error micropython content", file=sys.stderr)
  </script>

it works, but logs the following:

[Error] Unhandled Promise Rejection: ReferenceError: Cannot access uninitialized variable.
	(anonymous function) (error-CVKnHrMr.js:1:419)

I get this error twice if I use MicroPython and an external configuration file:

<script type="mpy" config="pyscript.toml">
    import sys
    print("This is normal micropython external content")
    print("This is error micropython external content", file=sys.stderr)
  </script>

where pyscript.toml contains:

plugins = ["!error"]

This error doesn't occur under Chrome (129.0.6668.101)

@freakboy3742
Copy link
Contributor Author

One other note that I mentioned in Discord, but mentioning it here for posterity: The existence of the errors plugin (and the option to turn it off) appears to have been purged from recent documentation. The 2024.04.1 documentation mentioned it (user guide > configuration > plugins); however, plugins are no longer mentioned in the configuration section of the docs, and the existence of the errors plugin isn't mentioned in the plugins section.

@WebReflection
Copy link
Contributor
WebReflection commented Oct 17, 2024

@freakboy3742 I have created a live example of your code and I cannot see any error whatsoever in there in WebKit (stable VS dev channel) https://pyscript.com/@agiammarchi/aged-frost/latest?files=main.py,index.html

edit yes, there are errors but those are not related to our code, rather PyScript .com concerns, nothing about the error

moreover, at position 419 the variable is the hooks one imported at the beginning of that very same file, the import {e} in there so I believe there is something else wrong going on? can you reproduce the error in Safari with my link?

We know about the documentation, it was "lost in translation" and I am bringing it back as we speak, thanks for pointing that out in both places though, appreciated!

@WebReflection
Copy link
Contributor
WebReflection commented Oct 17, 2024

Re-opening as the closing was done automatically from the MR + just FYI there is a new MR around plugins in our docs: pyscript/docs#146

edit if you can confirm everything is fine and you are happy now about the current state around error plugin, please let me know or feel free to close this issue yourself, thank you!

@WebReflection WebReflection reopened this Oct 17, 2024
@freakboy3742
Copy link
Contributor Author

I'm still seeing the "Unhandled promise rejection" using the example code you've provided (both in the console of Pyscript.com, and on a standalone html page - it reports as "line 10".).

Screenshot 2024-10-18 at 6 24 38 AM

If I comment out just L18 of your example (the definition of the errors plugin handling), the error goes away.

However, the actual error handling functionality seems to be working (both with an without the plugin)

@WebReflection
Copy link
Contributor

@freakboy3742 at line:
https://github.com/pyscript/pyscript/blob/main/core/src/plugins/error.js#L10

there is that e minified reference which can be found at line 2:
https://github.com/pyscript/pyscript/blob/main/core/src/plugins/error.js#L3

hooks are exported by core:
https://github.com/pyscript/pyscript/blob/main/core/src/core.js#L96

hooks are imported in core:
https://github.com/pyscript/pyscript/blob/main/core/src/core.js#L28-L35

hooks.main.onReady.add is defined synchronously too:
https://github.com/pyscript/pyscript/blob/main/core/src/hooks.js#L62-L105

I have some issue understanding how come everything works but you have an error in a crucial part of the logic ... and I've read this 3 times already and there is nothing that is not defined in here https://github.com/pyscript/pyscript/blob/main/core/src/plugins/error.js

could you please write down the exact string returned by navigator.userAgent out of devtools?

@freakboy3742
Copy link
Contributor Author

navigator.userAgent is returning "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15"

Full version from the About screen is Version 17.6 (19618.3.11.11.5), on macOS 14.7 (23H124).

@WebReflection
Copy link
Contributor
WebReflection commented Oct 18, 2024

I have Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15 but version is 17 ... this is so weird, I feel like it might be a bug in Safari ... even WebKit nightly is fine, and this is what I see
Screenshot From 2024-10-18 09-52-56

no promise error whatsoever ... is there any chance you either are importing PyScript twice or your cache is playing some weird trick?

@ntoll would you see a Promise error in this page with Safari? https://pyscript.com/@agiammarchi/aged-frost/latest?files=main.py,index.html

@freakboy3742
Copy link
Contributor Author

I'm using the same html content from the PyScript.com example snippet you've provided above, served with python -m http.server, so I don't think it can be a multiple-load problem.

As for a caching problem - I've just used a completely separate macOS laptop (running macOS 13.6.7 (22G720), with Safari Version 17.5 (18618.2.12.111.5, 18618), user agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15") - and on the first load of the page, I get the same error - twice.

Screenshot 2024-10-18 at 4 36 55 pm

For that matter- I get the same error (along with others) on the PyScript.com sandbox link you provided above.

Screenshot 2024-10-18 at 4 38 20 pm

@ntoll
Copy link
Member
ntoll commented Oct 22, 2024

@WebReflection here's what I see in my console:

Screenshot 2024-10-22 at 09 47 34

Note the promise rejection error that I expanded.

WebReflection added a commit to WebReflection/pyscript that referenced this issue Oct 24, 2024
WebReflection added a commit to WebReflection/pyscript that referenced this issue Oct 24, 2024
WebReflection added a commit to WebReflection/pyscript that referenced this issue Oct 24, 2024
WebReflection added a commit to WebReflection/pyscript that referenced this issue Oct 24, 2024
WebReflection added a commit to WebReflection/pyscript that referenced this issue Oct 24, 2024
@WebReflection
Copy link
Contributor

if you use https://cdn.jsdelivr.net/npm/@pyscript/core@0.6.12/dist/core.js instead of current generic one, unless jsdelivr already did catch up, you won't see that error anymore.

It's a horror story suitable for these days of the year but basically it got, eventually, fixed, and it's a Safari JS modules' resolution issue no other browser has so that an asynchronous operation in one import resolves before the importer gets a chance to use that code, and I am trying to recreate a minimal viable issue to file a proper bug at Safari / WebKit folks, although WebKit has no such issue whatsoever.

@freakboy3742
Copy link
Contributor Author

Can confirm that version of the script no longer raises the error. Thanks for the fix(es)!

@ntoll
Copy link
Member
ntoll commented Oct 25, 2024

FWIW @WebReflection does a deep dive into what was going on at the start of this week's PyScript FUN video: https://www.youtube.com/watch?v=_zbM5YtKrVA

WebReflection added a commit to WebReflection/pyscript that referenced this issue Oct 28, 2024
WebReflection added a commit that referenced this issue Oct 28, 2024
#2229)

* Fix #2220 - Delay plugins resolution due Safari 17.6 greedy resolution

* Fix #2228 - Workaround in Polyscript for lockFileURL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Issue needs triage type: bug Something isn't working
Projects
None yet
3 participants
0