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
[chore] Improve current Error extends #1467
Conversation
Personal Thoughts I have questioned myself the meaning of UserError as everything extends it ... and maybe answered my questions in the process, but:
In short, I think we could've used just throw new Error(`[${ErrorCode.value}] ${message}`) The |
/** | ||
* These error codes are used to identify the type of error that occurred. | ||
* TODO: describe in which case these are useful (or for who) as these are never used or shown. | ||
*/ |
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.
You are probably not done yet. I'm just thinking out loud while I glance over the PR. Yes, we should describe the error code categories, who are these for here but also add to the docs (arguably more important actually :) )
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.
We do have these in the docs under exceptions but I think we may not have all of them.
When I added this docstring the idea was to keep the reference in the code itself so devs can have a look and know which ones to raise.
With that said, I don't think we should remove them from the code :)
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.
Makes sense. That's what I first thought when I saw this change but I'm not too strongly opinionated (only that it should most definitely be in the docs). In general, 2 the options have pros and cons:
- having the codes here and in the docs means we need to make sure we are always updating in 2 places (which, in my experience, is really prone to error)
- having the codes only on the docs and having a link to the docs in the code (the info is less obvious to see from the source code but if a user wants, they can open docs)
Between the 2 options, I'm +0 keeping it on the docs only and having a link in the code (because, in most cases, comments can easily get outdated)
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.
I've updated the code to point at https://docs.pyscript.net/latest/reference/exceptions.html?highlight=errors which indeed seems like a very good idea
For context we raise UserError for the errors that we want to show a banner on the page, so far most of these tend to be user errors :) We used to have places where we were raising UserErrors with html formatting and others where we just send text that's why we used to have the param to do one or the other. I think the same is true for the logMessage Boolean but it's been a while since I wrote that code |
thanks for clarifying that part but it's not clear to me how these errors, not shown to users, not thrown edit We actually indeed show the error code as part of the message so my findings were wrong. |
Oh wait we aren't sending the error code? When I wrote this logic we were attaching both the error code and the error message to both the banner and the console something like:
Then in our docs under api exceptions we have the reference for these codes and some have suggestions for example this one when we can't install a package If I'm not mistaken we were adding the link to this reference in the error message when we try to install a package.
Did this change as well? Our codebase used to throw UserErrors like:
And then we used to have a general exception handler that would catch the UserError and handle it with creating the banner and logging the message if the flag was passed. But as I mentioned it's been a while since I looked at the code and I know a lot had changed haha I'm on holidays at the moment so it's a bit hard for me to look at the codebase with time to see if we still do all these things 😄 |
I need to dig into that too then, my apology for not tracking this better/further
so enjoy your holidays, there's no rush whatsoever around this chore related change and no need for you to dig into it but thanks for your answers and pointers so far! |
Ok, just to make sure I'm reading the intent correctly.
Do you mean that you need to raise |
That is correct we are catching |
@FabioRosado @fpliger this MR is finally green again after Jeff pinned the version of our pytest dependency ... feel free to approve or ask for changes as all points have been addressed now, thank you! |
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.
@WebReflection Thanks for your work here and also patience as I tried to understand what had changed in the codebase haha
I've added a comment which is mostly a question for myself, the PR looks great 😄
const closeButton = Object.assign(document.createElement('button'), { | ||
id: 'alert-close-button', | ||
innerHTML: CLOSEBUTTON, | ||
}); |
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.
I haven't seen this logic before, does this just create the object returned from createElement
with some extra attributes (id, innerHTML?)
This seems like a cool trick!
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.
Object.assign returns the target
(first argument) after attaching fields/properties via the object(s) that follow such target. In this specific case it makes multiple fields attached at once so that browsers/engine can also optimize when/if necessary in one shot, instead of two or more.
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.
TIL :)
Yeah, would be better to make it explicit. |
Though
Though I don't think type 3 exists. I think inheritance is a bad way to handle this situation because it's not very flexible. Maybe a good thing to do would be:
This way, if we catch an error, we are free to mark it as a This is basically the mechanism that Pyodide uses except that errors are considered to be a user error by default and if they are calculated to be internal errors then a special marker is placed on them. |
Yeah, good point. The main point I was trying to convey is that the type of error shouldn't necessarily be the only way you decide if an error makes it to the banner. Error types indicate the category of the errors and where these are displayed is a different [yet related] matter. |
Description
While digging into the dance around fetch files, I stumbled upon this file which looked a bit weird to me so I've decided to somehow apply the "boy-scout rule" and change it.
Changes
public
fields to simplify code and avoid redundant info / detailsappendChild
returned value to attach a listenerChecklist
docs/changelog.md