Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Handle errors as a lint message #1015

Merged
merged 7 commits into from
Sep 18, 2017
Merged

Conversation

Arcanemagus
Copy link
Member

@Arcanemagus Arcanemagus commented Sep 17, 2017

Handle errors as a lint message

Translate all errors coming from ESLint into a lint message instead of throwing them out to be caught by Linter's generic error catching mechanism. This allows us to present them in a much cleaner manner and
gives the user immediate feedback on what is going wrong.

Also includes several cleanups related to error handling to get a more unified experience with errors.

Before

Errors were only shown as an Atom error notification from Linter's generic catch-all:
image
Repeated lint requests would spam the message on the user's screen, providing a rather poor experience.

After

Errors coming from ESLint will show as a message in Linter, with the expandable message details showing the full stack trace:
Linter message:
image
Full details:
image

Fixes #387.

Since both function calls are using the same buffer, just change the
function to accept a TextBuffer and grab it before calling the function.
That function has 10 parameters, change it to an object so accidentally
re-ordering them won't cause major issues.
The only other code that could throw in that block is the
`validateRange` function, which would be the same issue (invalid point),
so it should be handled in the same manner.
This function isn't actually used any more and should have been deleted
back in #889.
Translate all errors coming from ESLint into a lint message instead of
throwing them out to be caught by Linter's generic error catching
mechanism. This allows us to present them in a much cleaner manner and
gives the user immediate feedback on what is going wrong.

Fixes #387.
@Arcanemagus
Copy link
Member Author

@IanVS This somewhat covers #883, but not fully which is why I didn't mark it as fixing that.

@skylize
Copy link
Contributor

skylize commented Sep 17, 2017

Love the idea. Not a big fan of the full page stack trace. That looks even more invasive than throwing an Atom error. Is there a plan to be able to suppress the stack until user explicitly requests it?

Edit: I think I misread. I guess that's exactly what you're doing already. Sweet! 👍 👍 👍

@Arcanemagus
Copy link
Member Author

Arcanemagus commented Sep 17, 2017

Updated the description to make it a bit clearer that the stack trace is only shown in the description of the message, an optionally displayed part that is meant to hold long form descriptions 😉.

The generally seen message (excerpt) is only the very first line of the error.message.

src/helpers.js Outdated
@@ -150,10 +133,25 @@ export async function generateDebugString(worker) {
return details.join('\n')
}

const generateInvalidTrace = async (
export async function handleError(textEditor, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, wrote this as async initially, but it doesn't actually need to be.

This function isn't async, don't mark it as such.
Copy link
Member

@IanVS IanVS left a comment

Choose a reason for hiding this comment

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

This is a nice user-experience improvement for sure. I don't think it should keep us from proceeding, but I do notice that the formatting isn't great in Nuclide (html tags are shown):

image

Other than that small concern and one minor question, I think this looks great and is much nicer than getting the error pop-ups.

msgLine, msgCol, msgEndLine, msgEndCol,
eslintFullRange, filePath, textEditor, ruleId, message, worker
) => {
}) => {
Copy link
Member

@IanVS IanVS Sep 17, 2017

Choose a reason for hiding this comment

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

😻

10 arguments is verging on ridiculous, good call making it an object.

) {
// This isn't an invalid point error from `generateRange`, re-throw it
throw err
}
Copy link
Member

Choose a reason for hiding this comment

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

Question

We are guaranteed that ruleId will be a string or undefined, right? I only ask, because if it's truthy but something other than a string, ruleURI() will throw a TypeError.

Copy link
Member Author

Choose a reason for hiding this comment

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

It comes straight from ESLint itself, so I'm not sure. I'll move that out of the try though just in case.

@Arcanemagus
Copy link
Member Author

Arcanemagus commented Sep 18, 2017

The formatting issue would be a bug with Nuclide, it's not our fault they can't properly render messages 😛. (description is supposed to be optionally shown and can be quite large... it was tested with entire web pages rendered in there for linter-ui-default.)

@Arcanemagus
Copy link
Member Author

Looks like they made the same mistake in atom-ide-ui, filed facebookarchive/atom-ide-ui#40 about it.

On the off chance that ESLint feeds us something that is truthy that
isn't a rule it could throw a `TypeError`, so move this out of the `try`
block for invalid points.
@Arcanemagus Arcanemagus force-pushed the arcanemagus/better-error-handling branch from 610b83c to a93881a Compare September 18, 2017 01:36
@Arcanemagus Arcanemagus merged commit 5353699 into master Sep 18, 2017
@Arcanemagus Arcanemagus deleted the arcanemagus/better-error-handling branch September 18, 2017 01:50
@skylize
Copy link
Contributor

skylize commented Sep 18, 2017

I feel like Thrown Errors should be distinguished in some way from Linter Errors (even if message details not expanded). Perhaps just prepend "Atom" or "Thrown" to the Severity? So you would see "Atom Error" for thrown errors and just "Error" for linting errors.

@Arcanemagus
Copy link
Member Author

The errors aren't from Atom though? As stated in the message, the error is coming from ESLint.

Errors that are thrown outside of the handled sections are still bubbled up to Linter/Atom.

@skylize
Copy link
Contributor

skylize commented Sep 18, 2017

Okay I understand. So it's an ESlint Error, but that name seems pretty meaningless since the linter errors are also from ESLint. "Thrown Error" or similar still makes to me here. I guess it's not hugely important. But if running in CLI, your output would be very very different from a thrown error vs a lint error. I feel like at least some little thing to clearly acknowledge this difference would be helpful.

@Arcanemagus
Copy link
Member Author

Do you have a better proposed text than the current Error while running ESLint: ${message}?

@skylize
Copy link
Contributor

skylize commented Sep 18, 2017

Hmm. I typed a few ideas out, but none of them seem any better except this:

** Error while running ESLint ** : $(message)

Stars are a text version of highlighting. We're just trying to point out that "Hey, this is a special error." It's typically fatal and will prevent any further linting, so it should be easy to tell instantly that it's not a typo in this file file that's causing it.

Stars in the Description text seems sufficient to me as visually indicating the extra severity, actually better than my initial proposal.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants