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

Combine CLI Errors. #2487

Merged
merged 10 commits into from
Jun 20, 2019
Merged

Combine CLI Errors. #2487

merged 10 commits into from
Jun 20, 2019

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Jun 10, 2019

Resolves #2474

Outside of core::JSError, all other Deno errors are now combined to be just DenoError.

I need to do further work on this PR, but wanted to get it visible to get any early feedback. Things I still need to do:

  • cli/errors.rs has no tests at all, add tests
  • Align the display of JSError (JSErrorColor) to be more like TypeScript diagnostics
  • Align the display of the other Deno errors to be more like TypeScript diagnostics
  • Bubble up non-diagnostic errors in the compiler worker

cli/errors.rs Outdated Show resolved Hide resolved
cli/errors.rs Outdated Show resolved Hide resolved
@kitsonk kitsonk force-pushed the deno_error branch 3 times, most recently from 9a7e219 to c7ee43d Compare June 17, 2019 10:27
@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 17, 2019

Ok, I have taken some artistic license with the errors to try to unify them, as neither TypeScript nor a coloured version of JSError work very well universally.

The biggest change is I took a hint from Rust errors which look something like this:

error[E0053]: method `format_related_info` has an incompatible type for trait
   --> ../../cli/fmt_errors.rs:122:26

Where TypeScript pretty errors led with the file location of the error, that really breaks up being to read them because on average, we output very long file identifiers that identify local and remote resources.

A TypeScript error looks like this (but in colour):

error TS2322: Type '(o: T) => { v: any; f: (x: B) => string; }[]' is not assignable to type '(r: B) => Value<B>[]'.
  Types of parameters 'o' and 'r' are incompatible.
    Type 'B' is not assignable to type 'T'.
      'B' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.

► file:///Users/kkelly/github/deno/tests/error_003_typescript.ts:20:3

20   values: o => [
     ~~~~~~

  The expected type comes from property 'values' which is declared here on type 'C<B>'

    ► file:///Users/kkelly/github/deno/tests/error_003_typescript.ts:8:3

    8   values?: (r: T) => Array<Value<T>>;
        ~~~~~~


error TS2339: Property 't' does not exist on type 'T'.

► file:///Users/kkelly/github/deno/tests/error_003_typescript.ts:22:12

22       v: o.t,
              ^


Found 2 errors.

And a JavaScript error looks like this:

error: Uncaught Error: exception from mod1
► file:///Users/kkelly/github/deno/tests/subdir/mod1.ts:16:9

16   throw Error("exception from mod1");
           ^

    at throwsError (file:///Users/kkelly/github/deno/tests/subdir/mod1.ts:16:9)
    at foo (file:///Users/kkelly/github/deno/tests/error_002.ts:4:3)
    at file:///Users/kkelly/github/deno/tests/error_002.ts:7:1

Also, I have remapped the top line, start_column, end_column and line contents from JSErrors, so you get authored code instead of transpiled code.

@ry ry marked this pull request as ready for review June 17, 2019 19:36
@ry
Copy link
Member

ry commented Jun 17, 2019

Why is the squiggly red in one place but teal in another

Screen Shot 2019-06-17 at 3 35 44 PM

I like the arrows

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 17, 2019

That follow the TypeScript model, squiggly red for an error, and squiggly teal/cyan for non-errors, where it is indicating a reference of where something is defined.

I should be able to finish off the tests today and get it into a green state.

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 18, 2019

For reference, Rust also uses cyan when underlining "help":

errors_rs_—_deno

@kitsonk kitsonk changed the title [WIP] Combine CLI Errors. Combine CLI Errors. Jun 18, 2019
@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 18, 2019

Ok, I think this is ready for a final review @ry.

I didn't tackle the other error kinds display, as these are intrinsically Rust errors and are generally handled differently (usually via a panic!()) which gives more Rust context by default.

Also, I didn't handle bubbling up the worker JavaScript errors. I suspect it would be more straightforward to do that in a seperate PR now that there is a unified error infrastructure.

@kitsonk kitsonk force-pushed the deno_error branch 2 times, most recently from e2bea3f to 7500a50 Compare June 19, 2019 03:13
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Just a couple nits - looks great!

cli/msg.fbs Show resolved Hide resolved
cli/main.rs Show resolved Hide resolved
cli/errors.rs Outdated Show resolved Hide resolved
cli/errors.rs Outdated Show resolved Hide resolved
cli/errors.rs Outdated Show resolved Hide resolved
cli/errors.rs Outdated Show resolved Hide resolved
cli/errors.rs Outdated Show resolved Hide resolved
cli/fmt_errors.rs Outdated Show resolved Hide resolved
core/modules.rs Show resolved Hide resolved
@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 20, 2019

@ry feedback addressed (and I forgot to test the source line remapping in source map, though it was being covered by the integrations tests).

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM

@ry ry merged commit 425df50 into denoland:master Jun 20, 2019
@kitsonk kitsonk deleted the deno_error branch August 2, 2022 04:45
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.

Unify Rust Error types
2 participants