Skip to content

Commit 5294a38

Browse files
committed
fix(lint): wrap string throws in Error to satisfy no-throw-literal
Replace throw "cancel" / throw "..." with throw new Error("...") in match-input.ts and dialogues.ts; update cancel-detection checks to instanceof Error + message === 'cancel'. #188
1 parent 0dc61b1 commit 5294a38

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/ext/dialogues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export class Dialogues {
342342
return value!;
343343
}
344344
this.ctrl.logger.debug("User canceled");
345-
throw "cancel";
345+
throw new Error("cancel");
346346
}
347347

348348

src/provider/commands/show-entry-for-date.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class AbstractLoadEntryForDateCommand implements vscode.Disposable {
4545
const doc = await this.loadPageForInput(input);
4646
await this.ctrl.ui.showDocument(doc);
4747
} catch (error) {
48-
if (error !== 'cancel') {
48+
if (!(error instanceof Error && error.message === 'cancel')) {
4949
this.ctrl.logger.error("Failed to load entry for input: ", input.text, "Reason: ", error);
5050
this.ctrl.ui.showError("Failed to open entry.");
5151
} else { return; }

src/provider/features/match-input.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ export class MatchInput {
4141
this.logger.trace("Entering parseInput() in features/InputMatcher.ts with input string '", inputString, "'");
4242

4343
if (isNullOrUndefined(inputString)) {
44-
throw "cancel";
44+
throw new Error("cancel");
4545
}
4646

4747
try {
4848
const parsedInput = new Input();
4949

5050
const res: RegExpMatchArray | null = inputString.match(this.getExpression());
5151
if (res === null) {
52-
throw "cancel";
52+
throw new Error("cancel");
5353
}
5454

5555
this.logger.trace(Object.entries(res!.groups!).map(([key, value]) => `${key}: ${value}`).join(', '));
@@ -63,7 +63,7 @@ export class MatchInput {
6363
const userProvidedTemporalToken = this.hasTemporalToken(res!);
6464

6565
if (parsedInput.hasFlags() && !parsedInput.hasMemo()) {
66-
throw "No text found for memo or task";
66+
throw new Error("No text found for memo or task");
6767
}
6868

6969
if (!parsedInput.hasFlags() && parsedInput.hasMemo()) {
@@ -90,7 +90,7 @@ export class MatchInput {
9090
} catch (error) {
9191
if (error instanceof Error) {
9292
this.logger.error("Failed to parse input from string '", inputString, "' do to reason: ", error.message);
93-
} else if (error !== "cancel") {
93+
} else if (!(error instanceof Error && error.message === "cancel")) {
9494
this.logger.error("Failed to parse input from string '", inputString, "'");
9595
}
9696
throw error;

0 commit comments

Comments
 (0)