Skip to content
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

Prevent hangs on internal errors #4126

Merged

Conversation

rhendric
Copy link
Member

@rhendric rhendric commented Jun 28, 2021

Description of the change

Sometimes, when one of our unit tests results in an internal error, the entire test process hangs. This is mildly annoying, and I think this PR is the appropriate fix? I have to confess that I don't have as solid an understanding of how MonadBaseControl works as I'd like. Also, our whole internal error story is kind of confusing to me—we have internalError, but also internalCompilerError, and a few instances of error scattered about to boot. I don't know if further enabling using the exception-based error functions instead of encouraging more use of the monadic internalCompilerError is the right thing to do.

Buuuuuut... this fix is quick and not too disruptive to the status quo, so I'm proposing it!


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@rhendric rhendric force-pushed the rhendric/fix-internal-error-hangs branch from 6c0e5f0 to 69ac52c Compare June 28, 2021 20:26
@JordanMartinez JordanMartinez mentioned this pull request Jul 2, 2021
5 tasks
@hdgarrood
Copy link
Contributor

I think internalError is the one we should be using everywhere. error should of course be avoided because it doesn't include any context or the suggestion to report the crash. I don't think a monadic function for internal errors is the best option; if we've encountered an internal error there's no hope of handling it, so I'm not sure I see the benefit of plumbing it through a transformer stack; all we can do with it is tell the user about it and exit. Also, we often want to use internalError in places where there's no monadic context to throw errors in. But maybe I'm missing something; I see internalCompilerError was introduced as part of polykinds so maybe @natefaubion can point out if I've missed something that makes using the monadic context more appealing.

@hdgarrood
Copy link
Contributor

The code looks reasonable but I'm a little bit hesitant to approve, just because of where this change is. Does this change only appear to affect the unit tests, or does it affect running the compiler normally as well?

@natefaubion
Copy link
Contributor

I see internalCompilerError was introduced as part of polykinds so maybe @natefaubion can point out if I've missed something that makes using the monadic context more appealing.

The error will get tagged with the source position of the thing it was checking when the internal error occured. This is incredibly useful.

@hdgarrood
Copy link
Contributor

Ok, that is very convincing. So maybe the approach should be “use internalCompilerError if you’re working in a context where it works, and internalError otherwise? Maybe we could rename them and/or add comments to make this a bit clearer.

@rhendric
Copy link
Member Author

Does this change only appear to affect the unit tests, or does it affect running the compiler normally as well?

It does affect the compiler running normally, but in a less dramatic way. Based on my tests, prior to this patch, an internal error usually causes the compiler to print only the error itself and purs: thread blocked indefinitely in an MVar operation before exiting. With this patch, the internal error is printed, any warnings (or errors?) produced in other files are also printed, and there is no MVar message.

Copy link
Contributor

@hdgarrood hdgarrood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then, that also sounds like an improvement.

@rhendric rhendric merged commit 7d286f8 into purescript:master Nov 12, 2021
@rhendric rhendric deleted the rhendric/fix-internal-error-hangs branch November 12, 2021 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants