-
-
Notifications
You must be signed in to change notification settings - Fork 866
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
Refactor loadPackage #1084
Refactor loadPackage #1084
Conversation
From the API point of view, this removes the messageCallback and errorCallback arguments in loadPackage, runPythonAsync etc. These are used for logging. Previously, any message will be written to the console, and then {message,error}Callback is called with the message as an argument. In most of our use cases, these callbacks do nothing. If we were to reintroduce this feature, I think we should introduce a logger interface, and users can supply custom loggers. This lets them choose to not output to stdout/stderr as well. Under the hood, the original motivation of this patch was to get rid of using packageCounter to determine whether all packages have been loaded. This is prone to error if we change the way we load packages (which I attempted in a different branch until I encountered an emscripten bug). One way or another, I ended up rewriting a lot of the code into something with a clearer control flow imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a stab at this. I still have lots of issues with this code but this is a clear and manageable improvement. I would have trouble leaving enough stuff alone to maintain a manageable diff (cf #998).
Maybe change toLoad
from an object to a Map
? I think that'd be better.
I think the windowErrorHandler
is really bad: what sorts of errors hit it and why? Can't we handle such errors in a less brute force way?
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Just for the record, the very original motivation was to get rid of our custom preloadWasm code and use the one that comes with emscripten, but turns out that's not compatible with |
See window.onerror:
I think we're trying to catch the second type of errors? So the correct way to do it is to attach an |
I think I am concerned mostly about the first kind of error within the loaded script. The second kind is captured by the |
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
It seems sad to be unable to catch the error any closer to the source, but if we add my noisy and explicit Incidentally, it's sort of remarkable that there isn't a less error prone and hacky way to load a script. Why doesn't the |
Well, we can fetch the source code and eval it .... |
Do we lose anything by doing that? Maybe weaker CORS restrictions? |
Maybe it's forbidden by "Content Security Policy" or something? |
Okay so if I understand correctly for the global window handler:
In that case I guess the most reasonable thing is just to put a comment explaining the situation and saying that it is technically necessary but unfortunate, and also to make it emit a noisy and explicit error message into the console if this happens. |
The main difference in end result in we no longer produce a hard error when errors occur during the dependency resolution stage; we simply ignore the offending packages. We still error if something goes wrong during package loading, as the system may be left in a broken state. The error messages produced are, however, slightly different. Now if a package is loaded from a custom url then the default channels, we no longer print it as an error; we assume the user is trying to override a dependency. Since we don't act on these errors anyway, this doesn't affect the API. Smaller changes include changing to a recursive DFS algorithm and turning toLoad into a Map
In our uses cases yes, but it would allow users to customize where errors/messages are shown.
In my understanding this feature is critical for downstream applications (e.g. Basthon, Starboard Notebook). Granted our error handling there can certainly be improved, but if we remove it we can't really make a release until a new API is includes. I think it would be better to,
Also for all changes that break backward compatibility and change the Public API, it would be better to have the changed method/arguments names in the title, as opposed to just "refactoring". Here this have been, |
In my understanding this feature is critical for downstream applications (e.g. Basthon, Starboard Notebook). Granted our error handling there can certainly be improved, but if we remove it we can't really make a release until a new API is includes. I think it would be better to,
- have a separate PR with as much of refactoring from this PR as possible
I'll re-introduce the callbacks into this PR
- open an issue and discuss how we want our error handling API to look. A logger might indeed be nice, but I also don't see it as fundamentally different from error callbacks. For instance #792 still has callbacks.
In my mind a logger interface is an object with ".log" and ".error"
functions, so basically combining the two into one. Perhaps I could just
do that and pass in console by default. But I'm thinking of using it
more pervasively, e.g. by default stdout/stderr should go there.
Also for all changes that break backward compatibility and change the Public API, it would be better to have the changed method/arguments names in the title, as opposed to just "refactoring". Here this have been, `API Remove messageCallback and errorCallback arguments from loadPackage`
Yeah this PR diverted from its original mission by *quite* a bit.
|
But I think I'll change the behaviour so that the default callbacks are console.log and console.error, and supplying a custom callback would cause it to stop logging to console. |
Yeah, that sound good. But let's still open an issue to discuss it before implementing it? I would like to also get feedback from downstream package maintainers. |
Yeah we should discuss with downstream whether they actually need an error callback. I think the right thing to do is to be able to request a logging level ("error", "warn", "info", "debug"). If they want to execute code when there is an error, what about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Should be good to merge unless @hoodmane has more comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really nice!
Okay this looks good to me, I think it should be accepted. |
From the API point of view, this removes the messageCallback and errorCallback arguments in loadPackage, runPythonAsync etc. These are used for logging. Previously, any message will be written to the console, and then {message,error}Callback is called with the message as an argument. In most of our use cases, these callbacks do nothing.
If we were to reintroduce this feature, I think we should introduce a logger interface, and users can supply custom loggers. This lets them choose to not output to stdout/stderr as well.
Under the hood, the original motivation of this patch was to get rid of using packageCounter to determine whether all packages have been loaded. This is prone to error if we change the way we load packages (which I attempted in a different branch until I encountered an emscripten bug).
One way or another, I ended up rewriting a lot of the code into something with a clearer control flow imo.