-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
gracefully handle error thrown from the service #249
gracefully handle error thrown from the service #249
Conversation
Also, currently the error object is too complex to be passed over the thread boundary, so only an empty object will arrive on the parent thread. I'll address that in a second commit, just wanted to already get my questions out to you guys. |
Okay, errors are now correctly serialized, too. I tried this in single-thread mode and also in cluster mode by manually throwing an Error from within the service - in both cases, the error is correctly logged. If you are fine with passing these errors to the Again, sorry for the hassle - I had noticed this problem earlier today, but I had not anticipated it to be merged so quickly after @johnnyreilly was still testing, otherwise I would have notified you about this immediately. |
Cool. Do you want to update the
What's super important here is that these sort of errors fail the build. We want to avoid the situation where someone builds, there's an error but the build is considered passing. That way leads to errors in production. Given that it's only really running with I'm okay with a new hook like Errors reported using this mechanism already get surfaced to webpack / the notifier etc. Can we consider using that? I'm mindful that it may not be a perfect fit and we shouldn't force it if it's not. But if it works then that's pretty straightforward. |
@johnnyreilly actually, using |
f1a4d2a
to
c1d25d6
Compare
Okay, completely different approach. Now internal errors are just reported as diagnostics, but as a sepearate type of NormalizedMessage. Everything else just happens in the formatter. Do you think that is feasible or should those error be passed as a separate array next to diagnostics and lints? That array could be added as a third argument to the |
c1d25d6
to
576b134
Compare
I think this is good!
For exactly that reason I want to treat them as diagnostics. I'm mindful of third parties consuming this and aiming for a non-breaking changes approach. I think the introduction of a 3rd type of I wonder if we could take your idea and tweak it a little. Instead of a new So maybe
But in the case we're talking about we use the |
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.
What do you think of the approach suggested below? It means even less code changes. It slightly overloads code
of NormalizedMessage` but not in a way that should be problematic. (I think)
BTW once we're settled on how this should work, would you be able to add an integration test to ensure we've got this covered please?
Out of interest (and I really should have asked this question earlier 😄 ) - what happened with the pre-worker-rpc
fork-ts-checker-webpack-plugin
in the case of unhandled errors? How was behaviour different?
src/formatter/codeframeFormatter.ts
Outdated
@@ -22,6 +22,16 @@ export function createCodeframeFormatter(options: any) { | |||
: colors.bold.red; | |||
const positionColor = colors.dim; | |||
|
|||
if (message.isInternalType()) { |
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 won't need this anymore
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.
Unfortunately I think we still do - internal errors have no useful file, line or column to display, but they have a stack trace. So those still need to be displayed separately.
I could try to parse the file name, line and column from the stack trace, but given that's just a string that might fail in different node versions if the formatting changes or something alike. Also, a stack trace has multiple filenames/lines/columns, so without separate handling that extra information might get lost.
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.
These are valid points....
Hmmmm......
I really want to avoid having another error type because of consumers like create-react-app
etc rolling their own formatters.
Given that, as I understand it, this the edgiest of edge cases.... i.e we don't expect this to happen once in a blue moon then perhaps it's not the end of the world.
What's your view?
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 think it doesn't hurt this way. The stack
is additional information and file
, line
and character
are optional properties, so every formatter should have to check for those to exist anyways (and in the worst case, it would display error in file [internal], undefined:undefined
).
With a formatter not supporting this, the users would see the error and that it occured, they might just not get all the information available.
The only thing I'm not 100% sure about is that file
would currently contain [internal]
, which might pose problems if the formatter just tries to read the file without checking for it's existence.
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.
The only thing I'm not 100% sure about is that file would currently contain [internal], which might pose problems if the formatter just tries to read the file without checking for it's existence.
I'm pretty sure it doesn't. Let's go with this.
That's fine with me. Although it would still need minor modifications to the formatter to display the stack trace (I tried adding that to content, but thats not really nice with pop-up-notifications ;) ).
I can try, although I'm not sure how to forcefully make it throw an error without doing something like if (process.env.TEST_FORCE_THROW_ERROR === "true") { throw new Error("test!"); } in the production codebase. Would you be fine with something like that? And if yes, where would you put it?
Before, the thread would just be gone for good without anyone ever noticing, except maybe for some noise on the console 😆 |
No - let's not!
Ah well this will be an improvement then! |
I assumed as much. Do you have any other idea on how to trigger this? PS: And yeah, I thought of mocking a require, but that won't help since that will only mock on the same thread, but not on a different one :( |
I don't. Given it's an edge case I don't think it's the end of the world if we don't have an integration test. A unit test might be doable though? |
@johnnyreilly actually, I found a way to do a proper integration test - using Actually, I think this is might even be useful for other tests to inject some code 😃 I'll add your suggested changes for |
Okay, did as you requested and additionally, I moved the code for creating a NormalizedMessage from Only thing that I think we can't do as you requested is this comment - I replied inline: #249 (comment) |
Cool - I've responded to your response 😊 |
Since there seems to be no email notification on those comments: I responded to your response to my response ;) |
This needs some clarification - I'll add some in-code-comments.
PS: no need for panic, the current 1.0.3 should not break anything for anyone.
This only addresses the case where Errors are thrown within the service (which should not happen in the first place) and in that case the 1.0.3 behaviour should only be logging an "uncaught promise" warning and nothing grave should happen.
I just had hoped to get this into the release, because it was clearly missing :/