Skip to content

Commit c1ab265

Browse files
committed
improved error output of string exceptions
1 parent dd5d1ea commit c1ab265

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to the "prettier-vscode" extension will be documented in thi
44

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

7+
## [5.1.3]
8+
9+
- Improved error output of certain plugin exceptions.
10+
711
## [5.1.2]
812

913
- Added error logging for unusual prettier exceptions.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "prettier-vscode",
33
"displayName": "Prettier - Code formatter",
44
"description": "Code formatter using prettier",
5-
"version": "5.1.2",
5+
"version": "5.1.3",
66
"publisher": "esbenp",
77
"author": "Prettier <@prettiercode>",
88
"galleryBanner": {

src/LoggingService.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,23 @@ export class LoggingService {
4646
}
4747
}
4848

49-
public logError(message: string, error?: Error) {
49+
public logError(message: string, error?: Error | string) {
5050
if (this.logLevel === "NONE") {
5151
return;
5252
}
5353
this.logMessage(message, "ERROR");
54-
if (error?.message || error?.stack) {
55-
// Try to print the most useful error message
54+
if (typeof error === "string") {
55+
// Errors as a string usually only happen with
56+
// plugins that don't return the expected error.
57+
this.outputChannel.appendLine(error);
58+
} else if (error?.message || error?.stack) {
5659
if (error?.message) {
5760
this.logMessage(error.message, "ERROR");
5861
}
5962
if (error?.stack) {
6063
this.outputChannel.appendLine(error.stack);
6164
}
6265
} else if (error) {
63-
// Weird error returned, just output the whole thing
6466
this.logObject(error);
6567
}
6668
}

0 commit comments

Comments
 (0)