Skip to content

Commit c74557c

Browse files
committed
fix: improved error message when swiftformat is missing
1 parent 8e38f76 commit c74557c

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.6.1
2+
3+
- fix: improved error message when swiftformat is missing
4+
15
# 1.6.0
26

37
- docs: clarified `swiftformat.options` #17

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/vknabel/vscode-swiftformat"
88
},
9-
"version": "1.6.0",
9+
"version": "1.6.1",
1010
"license": "MIT",
1111
"author": {
1212
"name": "Valentin Knabel",

src/UserInteraction.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Current from "./Current";
33

44
enum FormatErrorInteraction {
55
configure = "Configure",
6-
reset = "Reset"
6+
reset = "Reset",
7+
howTo = "How?"
78
}
89

910
enum UnknownErrorInteraction {
@@ -14,21 +15,32 @@ export async function handleFormatError(
1415
error: any,
1516
document: vscode.TextDocument
1617
) {
17-
if (error.code === "ENOENT") {
18+
function matches(...codeOrStatus: Array<number | string>) {
19+
return codeOrStatus.some(c => c === error.code || c === error.status);
20+
}
21+
if (matches("ENOENT", 127)) {
1822
const selection = await Current.editor.showErrorMessage(
19-
`Could not find SwiftFormat: ${Current.config.swiftFormatPath(document)}`,
23+
`Could not find SwiftFormat: ${Current.config
24+
.swiftFormatPath(document)
25+
?.join(" ")}.\nEnsure it is installed and in your PATH.`,
2026
FormatErrorInteraction.reset,
21-
FormatErrorInteraction.configure
27+
FormatErrorInteraction.configure,
28+
FormatErrorInteraction.howTo
2229
);
2330
switch (selection) {
2431
case FormatErrorInteraction.reset:
25-
await Current.config.resetSwiftFormatPath();
32+
Current.config.resetSwiftFormatPath();
2633
break;
2734
case FormatErrorInteraction.configure:
28-
await Current.config.configureSwiftFormatPath();
35+
Current.config.configureSwiftFormatPath();
36+
break;
37+
case FormatErrorInteraction.howTo:
38+
await Current.editor.openURL(
39+
"https://github.com/nicklockwood/SwiftFormat#command-line-tool"
40+
);
2941
break;
3042
}
31-
} else if (error.status === 70) {
43+
} else if (matches(70)) {
3244
await Current.editor.showErrorMessage(
3345
`SwiftFormat failed. ${error.stderr || ""}`
3446
);

0 commit comments

Comments
 (0)