Skip to content

Report internal errors more clearly #5661

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

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from

Conversation

sellout
Copy link
Contributor

@sellout sellout commented Apr 23, 2025

Overview

Internal errors are rather opaque. In #4463, we see

scratch/main> run main

   renameTo: duplicate rename

this adds more context, so now we have

scratch/main> run main

  ❗️

  You’ve discovered an internal bug in the Unison runtime!

    renameTo: duplicate rename

  See if one of these issues at
  https://github.com/unisonweb/unison/issues reflects what
  you’re seeing. If not, please open a new one:
  * 3625
  * 4463

Test coverage

There is a new transcript to replicate #4463, which does exercise this, but it will stop exercising it once that issue is fixed. But perhaps more reproductions will be added in the meantime …

I recommend reviewing commit-by-commit.

sellout added 4 commits April 22, 2025 23:18
- `CompileExn` and `internalBug` have been moved to a new module and had
  duplicate implementations removed,
- `internalBug` has a much richer message that should be more helpful to
  users,
- `internalBug` now accepts a list of issue numbers relevant to that
  message, and
- exception-related imports are now more explicit.

Also, there are a couple open questions tagged with __TODO__.
Previously there were three ways of handling optional `Width`

1. distinct `x` and `xUnbroken` functions,
2 `Maybe Width`, and
3 `Width 0` implies “unbroken”.

Since it’s difficult to use strictly positive numeric types[^1], this
now consistently treats `width <= 0`[^2] as “unbroken”.

[^1]: If it weren’t, I would have preferred something like `Maybe
      Positive`.

[^2]: It would be nice to define `Width` using something like `Word`
      instead of `Int`, which would allow `width == 0`, but that has
      cascading impacts across functions like `length` and `replicate`,
      which makes it more intrusive.

This also results in a couple inconsequential semantic changes to
“unbroken” rendering:

- “unbroken” is truly unbroken, not limited to `maxBound :: Int`
- right-aligning `Pretty` output (which isn’t currently used anyway)
  would do nothing in the “unbroken” case, rather than padding the
  output to `maxBound :: Int` columns.
@sellout sellout force-pushed the improve-internal-errors branch from 84a2d1b to 9b252cc Compare April 23, 2025 19:59
@sellout sellout requested a review from a team as a code owner April 23, 2025 19:59
@aryairani
Copy link
Contributor

Hey this looks great. Two thoughts:

  1. I think it'd be better if we could pass a super short description of what could be causing it, too:
scratch/main> run main

  ❗️

  Sorry — I've encountered a bug in the Unison runtime.

    renameTo: duplicate rename

  Please check if one of these known issues matches your situation:

  * repeated variable names in pattern match cause "duplicate rename" error
    https://github.com/unisonweb/unison/issues/4463

  If not, please open a new one:
  https://github.com/unisonweb/unison/issues/new/choose

Sorry I ended up making this a bad example by closing 3625 as a duplicate 😅 but yes it should take a list like you have already done.

  1. We probably shouldn't set runtime_tests_version to your personal branch; can those changes be PRed into the runtime tests, and then we update here to 0.0.4?

@sellout
Copy link
Contributor Author

sellout commented Apr 24, 2025

  1. I think it'd be better if we could pass a super short description of what could be causing it, too:

Ah, yeah – I should have included this under “loose ends”. I was thinking we could fetch the title via the GitHub API, so the internalBug call sites still just have the issue number, but (as long as we don’t use displayException, which eschews IO) we could get the title dynamically.

  1. We probably shouldn't set runtime_tests_version to your personal branch; can those changes be PRed into the runtime tests, and then we update here to 0.0.4?

Yeah, I was following the instructions in interpreter-tests.md. I figured I shouldn’t open a contribution until this PR is stabilized (e.g., you suggestions will require an update to my runtime-tests branch).

@sellout sellout force-pushed the improve-internal-errors branch from 8384155 to 26428cd Compare April 26, 2025 04:09
sellout added 3 commits April 26, 2025 12:33
- rephase
- include GitHub issue titles when possible
`Unison.Runtime.Exception.die` is overridden in `Machine.Types`, and
most call sites end up inheriting and using that instead. This just
folds the minor alteration of that version into the one in `Exception`.
@sellout sellout force-pushed the improve-internal-errors branch from 8754c04 to 37d85c8 Compare April 26, 2025 18:52
@aryairani
Copy link
Contributor

Ah, yeah – I should have included this under “loose ends”. I was thinking we could fetch the title via the GitHub API, so the internalBug call sites still just have the issue number, but (as long as we don’t use displayException, which eschews IO) we could get the title dynamically.

yeah that could work; we just have to remember to apply short github titles in that case

Yeah, I was following the instructions in interpreter-tests.md. I figured I shouldn’t open a contribution until this PR is stabilized (e.g., you suggestions will require an update to my runtime-tests branch).

My bad. Ok so we'll stabilize the PR, then open the contribution for /runtime-tests, make a release, and update the PR, and then merge it?

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.

2 participants