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

Report unhandled errors, but only those that are from our extension #2125

Merged
merged 1 commit into from
Mar 3, 2023

Conversation

robertbrignull
Copy link
Contributor

@robertbrignull robertbrignull commented Mar 1, 2023

This is a second attempt at #2076. That PR worked a bit too well, in that it was picking up errors from other extensions and presenting them to the user. The fix for this that we discussed was to check the stack trace to see if it's from our extension or somewhere else.

I've implemented this by checking for /extensions/ql-vscode/. I couldn't think of a better string to check for. We might actually have trouble in the future if we move the extension to the top level of the repo. I'm not sure if that means we should look for a different approach now, or save that problem for if/when we do move the code in the repo.

I've tested this using https://github.com/robertbrignull/error-extension. I created a new extension (from a template) that provides commands that intentionally throw errors and reject promises. Using this I was able to reproduce the existing bad behaviour and then also show that we now don't report errors from other extensions.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@robertbrignull robertbrignull requested a review from a team March 1, 2023 13:19
@robertbrignull robertbrignull requested a review from a team as a code owner March 1, 2023 13:19
Comment on lines 1576 to 1580
// The stack trace gets redacted before being sent as telemetry, but at
// this point in the code we have the full unredacted information.
const isFromThisExtension = getErrorStack(error).includes(
"/extensions/ql-vscode/",
);
Copy link
Member

Choose a reason for hiding this comment

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

Have you tested this using a packaged extension (VSIX)? I believe the stack trace in the packaged extension looks something like shown in the source map script:

Error: Failed to find CodeQL distribution.
     at CodeQLCliServer.getCodeQlPath (/Users/user/.vscode/extensions/github.vscode-codeql-1.7.8/out/extension.js:131164:13)
     at CodeQLCliServer.launchProcess (/Users/user/.vscode/extensions/github.vscode-codeql-1.7.8/out/extension.js:131169:24)
     at CodeQLCliServer.runCodeQlCliInternal (/Users/user/.vscode/extensions/github.vscode-codeql-1.7.8/out/extension.js:131194:24)
     at CodeQLCliServer.runJsonCodeQlCliCommand (/Users/user/.vscode/extensions/github.vscode-codeql-1.7.8/out/extension.js:131330:20)
     at CodeQLCliServer.resolveRam (/Users/user/.vscode/extensions/github.vscode-codeql-1.7.8/out/extension.js:131455:12)
     at QueryServerClient2.startQueryServerImpl (/Users/user/.vscode/extensions/github.vscode-codeql-1.7.8/out/extension.js:138618:21)

This does not include /extensions/ql-vscode because when the extension is packaged, that part of the path is not included.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I was testing with the development host rather than a packaged extension. If the paths do always look like the ones you've included here, that looks very promising for a robust way to detect extension code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've rewritten this check to use extension.extensionPath instead, which will be much more accurate. It'll also avoid issues on windows because I accidentally used forward slashes in the previous implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This time I tested using a vsix that I build and installed.

@robertbrignull
Copy link
Contributor Author

Thanks @koesie10 for the earlier review. It's ready for re-review now.

Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Nice...LGTM assuming the answer to my question is "yes".

Comment on lines +1587 to +1589
const isFromThisExtension =
extension && getErrorStack(error).includes(extension.extensionPath);

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice...so this will handle the local development case as well as bundled extensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does still work for local development, because the extension path still matches the location of the installed extension. In my case it's /Users/robertbrignull/github/vscode-codeql/extensions/ql-vscode.

Copy link
Member

@koesie10 koesie10 left a comment

Choose a reason for hiding this comment

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

LGTM

@robertbrignull robertbrignull merged commit e9bbf11 into main Mar 3, 2023
@robertbrignull robertbrignull deleted the robertbrignull/error_listener branch March 3, 2023 11:34
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.

3 participants