Skip to content

Commit

Permalink
fix: improved error message when swiftformat is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Dec 23, 2022
1 parent 8e38f76 commit c74557c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.6.1

- fix: improved error message when swiftformat is missing

# 1.6.0

- docs: clarified `swiftformat.options` #17
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/vknabel/vscode-swiftformat"
},
"version": "1.6.0",
"version": "1.6.1",
"license": "MIT",
"author": {
"name": "Valentin Knabel",
Expand Down
26 changes: 19 additions & 7 deletions src/UserInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import Current from "./Current";

enum FormatErrorInteraction {
configure = "Configure",
reset = "Reset"
reset = "Reset",
howTo = "How?"
}

enum UnknownErrorInteraction {
Expand All @@ -14,21 +15,32 @@ export async function handleFormatError(
error: any,
document: vscode.TextDocument
) {
if (error.code === "ENOENT") {
function matches(...codeOrStatus: Array<number | string>) {
return codeOrStatus.some(c => c === error.code || c === error.status);
}
if (matches("ENOENT", 127)) {
const selection = await Current.editor.showErrorMessage(
`Could not find SwiftFormat: ${Current.config.swiftFormatPath(document)}`,
`Could not find SwiftFormat: ${Current.config
.swiftFormatPath(document)
?.join(" ")}.\nEnsure it is installed and in your PATH.`,
FormatErrorInteraction.reset,
FormatErrorInteraction.configure
FormatErrorInteraction.configure,
FormatErrorInteraction.howTo
);
switch (selection) {
case FormatErrorInteraction.reset:
await Current.config.resetSwiftFormatPath();
Current.config.resetSwiftFormatPath();
break;
case FormatErrorInteraction.configure:
await Current.config.configureSwiftFormatPath();
Current.config.configureSwiftFormatPath();
break;
case FormatErrorInteraction.howTo:
await Current.editor.openURL(
"https://github.com/nicklockwood/SwiftFormat#command-line-tool"
);
break;
}
} else if (error.status === 70) {
} else if (matches(70)) {
await Current.editor.showErrorMessage(
`SwiftFormat failed. ${error.stderr || ""}`
);
Expand Down

0 comments on commit c74557c

Please sign in to comment.