Skip to content

Commit

Permalink
improved error output of string exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Jul 2, 2020
1 parent dd5d1ea commit c1ab265
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "prettier-vscode" extension will be documented in thi

<!-- Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. -->

## [5.1.3]

- Improved error output of certain plugin exceptions.

## [5.1.2]

- Added error logging for unusual prettier exceptions.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "prettier-vscode",
"displayName": "Prettier - Code formatter",
"description": "Code formatter using prettier",
"version": "5.1.2",
"version": "5.1.3",
"publisher": "esbenp",
"author": "Prettier <@prettiercode>",
"galleryBanner": {
Expand Down
10 changes: 6 additions & 4 deletions src/LoggingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,23 @@ export class LoggingService {
}
}

public logError(message: string, error?: Error) {
public logError(message: string, error?: Error | string) {
if (this.logLevel === "NONE") {
return;
}
this.logMessage(message, "ERROR");
if (error?.message || error?.stack) {
// Try to print the most useful error message
if (typeof error === "string") {
// Errors as a string usually only happen with
// plugins that don't return the expected error.
this.outputChannel.appendLine(error);
} else if (error?.message || error?.stack) {
if (error?.message) {
this.logMessage(error.message, "ERROR");
}
if (error?.stack) {
this.outputChannel.appendLine(error.stack);
}
} else if (error) {
// Weird error returned, just output the whole thing
this.logObject(error);
}
}
Expand Down

0 comments on commit c1ab265

Please sign in to comment.