Skip to content

Prevent hangs on internal errors#4126

Merged
rhendric merged 1 commit intopurescript:masterfrom
rhendric:rhendric/fix-internal-error-hangs
Nov 12, 2021
Merged

Prevent hangs on internal errors#4126
rhendric merged 1 commit intopurescript:masterfrom
rhendric:rhendric/fix-internal-error-hangs

Conversation

@rhendric
Copy link
Copy Markdown
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
@rhendric rhendric force-pushed the rhendric/fix-internal-error-hangs branch from 69ac52c to 6e56f51 Compare July 12, 2021 21:46
@hdgarrood
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

4 participants