Standardize language server errors#1429
Conversation
4d58675 to
376ae1b
Compare
| export class Debug { | ||
| public static connection?: IConnection; | ||
|
|
||
| public static SetConnection(conn: IConnection) { |
There was a problem hiding this comment.
using a static connection in this class, so we don't need to instantiate the class and pass it around anywhere. The user can just import the class itself from this file and call it without worrying like in the workspace file below
| ...existingProjects, | ||
| ...projectsForConfig | ||
| ]); | ||
| if (config) { |
There was a problem hiding this comment.
Had to modify this file to be able to accept null configs. Since the new pattern would be to return empty responses and log errors, we'll need to do this a few places.
|
|
||
| const config = await this.createConfig(flags); | ||
|
|
||
| if (!config) { |
There was a problem hiding this comment.
Configs can now be null :)
There was a problem hiding this comment.
I use this.error and this.exit here because there aren't many errors that happen in the CLI itself. Most happen in the language server.
Errors in the CLI already have a handler (this.error) and should return with an exit code of 1. We could wrap this up into another function but I don't see the need yet.
| // for errors (and other logs in debug mode) we want to print a stack trace showing where they were thrown. | ||
| // This uses an Error's stack trace, removes the three frames regarding this file (since they're useless) and | ||
| // returns the rest of the trace. | ||
| const createAndTrimStackTrace = () => { |
There was a problem hiding this comment.
I think it's okay that this logic is duplicated in multiple places (language server and here) since it's only one thing, we don't have a great place to put it, and we could change the formatting based on where it is later.
| */ | ||
| public static error(message: string, stack?: string) { | ||
| const stackTrace = stack || createAndTrimStackTrace(); | ||
| Debug.showConsole(); |
There was a problem hiding this comment.
since errors are urgent, show the output window
| * TODO: enable error reporting and telemetry | ||
| * Displays and warning message prefixed with [WARN] | ||
| */ | ||
| // public static sendErrorTelemetry(message: string) { |
There was a problem hiding this comment.
We could use this to track errors that are thrown in sentry/google analytics/something else.
trevor-scheer
left a comment
There was a problem hiding this comment.
Minor, non-blocking stuff! Can't wait to see the future of error handling :)
87c6c8f to
b466e70
Compare
* Add debug logging utils for language server and vs code * Add stack traces to debug errors * moved config loader to use debug util
This PR is the result of investigating how other implementations of the language server protocol handle errors. This PR proposes a new method of handling errors across the language server and its clients (CLI and VS Code). The intention is to produce a more friendly, consistent means by which to log and handle errors, as well as set up the basis for what could become usage metrics and error reporting, and verbose/debugging modes.
The state of things now
Proposed Solution
At a high level, this method would eliminate the throwing of errors, and rely on errors being passed as notifications from the server to a client. For clients that don't consume the language server from a JSON-RPC transport (like the CLI which calls it directly) the server's error mechanism would be to fallback to console logs and errors.
The key with this proposal is to ONLY have graceful exits from the language server. If something goes wrong, we should explain the error and do nothing. Failing out completely isn't great. Instead, clients should see empty responses from failed operations.
Debugclasses on the client (vscode) and server.Debugclass is responsible for printing errors, warnings, and info messages to the console. In CLI projects (or whereconnectionis unavailable), the util willlog/warn/errorto the consoleDebugclass is responsible to notifying the client of errors via theserverDebugMessagenotification.serverDebugMessagenotification handler on the client which calls theDebugclass methods to display errors to the user.Debugmodule and removing the unhelpful frames.Debugmodule of the client.-vor--verbosemode where errors and warnings have traces. We could also make sure those stacks aren't trimmed.[INFO]messages could be used for debug logs (maybe)Notes:
debugmode (not implemented) and telemetry (not implemented).Future work:
Debugclass could allow for a separate error logger to be passed to it to support arbitrary clients that can't support console logs or notifications from the LSP, but since we don't have any clients for that, we shouldn't worry about that right now.TODO:
*Make sure changelog entries note which project(s) has been affected. See older entries for examples on what this looks like.