Skip to content

Commit 7f8888e

Browse files
committed
fix: improve error handling in main.ts and quickAddApi.ts
1 parent c32d409 commit 7f8888e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/main.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import type { TFile } from "obsidian";
22
import { Plugin } from "obsidian";
33
import { DEFAULT_SETTINGS, QuickAddSettingsTab } from "./quickAddSettingsTab";
44
import type { QuickAddSettings } from "./quickAddSettingsTab";
5-
import { log, toError } from "./logger/logManager";
5+
import { log } from "./logger/logManager";
66
import { ConsoleErrorLogger } from "./logger/consoleErrorLogger";
77
import { GuiLogger } from "./logger/guiLogger";
88
import { LogManager } from "./logger/logManager";
9+
import { reportError } from "./utils/errorUtils";
910
import { StartupMacroEngine } from "./engine/StartupMacroEngine";
1011
import { ChoiceExecutor } from "./choiceExecutor";
1112
import type IChoice from "./types/choices/IChoice";
@@ -109,8 +110,9 @@ export default class QuickAdd extends Plugin {
109110
const choice = this.getChoice("name", parameters.choice);
110111

111112
if (!choice) {
112-
log.logError(
113-
`URI could not find any choice named '${parameters.choice}'`,
113+
reportError(
114+
new Error(`URI could not find any choice named '${parameters.choice}'`),
115+
"URI handler error"
114116
);
115117
return;
116118
}
@@ -125,7 +127,7 @@ export default class QuickAdd extends Plugin {
125127
try {
126128
await choiceExecutor.execute(choice);
127129
} catch (err) {
128-
log.logError(toError(err));
130+
reportError(err, "Error executing choice from URI");
129131
}
130132
});
131133

src/quickAddApi.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import GenericCheckboxPrompt from "./gui/GenericCheckboxPrompt/genericCheckboxPr
77
import type { IChoiceExecutor } from "./IChoiceExecutor";
88
import type QuickAdd from "./main";
99
import type IChoice from "./types/choices/IChoice";
10-
import { log } from "./logger/logManager";
10+
import { reportError } from "./utils/errorUtils";
1111
import { CompleteFormatter } from "./formatters/completeFormatter";
1212
import { getDate } from "./utilityObsidian";
1313
import { MarkdownView } from "obsidian";
@@ -70,7 +70,7 @@ export class QuickAddApi {
7070
) => {
7171
const choice: IChoice = plugin.getChoiceByName(choiceName);
7272
if (!choice)
73-
log.logError(`choice named '${choiceName}' not found`);
73+
reportError(new Error(`Choice named '${choiceName}' not found`), "API executeChoice error");
7474

7575
if (variables) {
7676
Object.keys(variables).forEach((key) => {
@@ -171,7 +171,7 @@ export class QuickAddApi {
171171
);
172172

173173
if (!assistantRes) {
174-
log.logError("AI Assistant returned null");
174+
reportError(new Error("AI Assistant returned null"), "AI Prompt error");
175175
return {};
176176
}
177177

@@ -262,7 +262,7 @@ export class QuickAddApi {
262262
);
263263

264264
if (!assistantRes) {
265-
log.logError("AI Assistant returned null");
265+
reportError(new Error("AI Assistant returned null"), "Chunked AI Prompt error");
266266
return {};
267267
}
268268

@@ -301,14 +301,12 @@ export class QuickAddApi {
301301
app.workspace.getActiveViewOfType(MarkdownView);
302302

303303
if (!activeView) {
304-
log.logError(
305-
"no active view - could not get selected text."
306-
);
304+
reportError(new Error("No active view"), "Could not get selected text");
307305
return;
308306
}
309307

310308
if (!activeView.editor.somethingSelected()) {
311-
log.logError("no text selected.");
309+
reportError(new Error("No text selected"), "Could not get selected text");
312310
return;
313311
}
314312

@@ -422,4 +420,4 @@ export class QuickAddApi {
422420
return undefined;
423421
}
424422
}
425-
}
423+
}

0 commit comments

Comments
 (0)