diff --git a/packages/common/src/types/commandHistory.ts b/packages/common/src/types/commandHistory.ts index 8af2a3aa52..93435a0ca2 100644 --- a/packages/common/src/types/commandHistory.ts +++ b/packages/common/src/types/commandHistory.ts @@ -3,12 +3,15 @@ import type { CommandComplete } from "./command/command.types"; /** * Represents a single line in a command history jsonl file. */ -export interface CommandHistoryItem { - // eg: "2023-09-05" +export interface CommandHistoryEntry { + // Date of the log entry. eg: "2023-09-05" date: string; - // eg: "0.28.0-c7bcf64d" + // Version of the Cursorless extension. eg: "0.28.0-c7bcf64d" cursorlessVersion: string; + // Name of thrown error. eg: "NoContainingScopeError" + thrownError?: string; + command: CommandComplete; } diff --git a/packages/cursorless-vscode/src/CommandHistory.ts b/packages/cursorless-vscode/src/CommandHistory.ts index 3e6b74b813..4b235af5ca 100644 --- a/packages/cursorless-vscode/src/CommandHistory.ts +++ b/packages/cursorless-vscode/src/CommandHistory.ts @@ -1,7 +1,7 @@ import { ActionDescriptor, CommandComplete, - CommandHistoryItem, + CommandHistoryEntry, Disposable, FileSystem, ReadOnlyHatMap, @@ -55,21 +55,32 @@ export class CommandHistory implements CommandRunnerDecorator { return { run: async (commandComplete: CommandComplete) => { - await this.appendToLog(commandComplete); + try { + const returnValue = await runner.run(commandComplete); - return await runner.run(commandComplete); + await this.appendToLog(commandComplete); + + return returnValue; + } catch (e) { + await this.appendToLog(commandComplete, e as Error); + throw e; + } }, }; } - private async appendToLog(command: CommandComplete): Promise { + private async appendToLog( + command: CommandComplete, + thrownError?: Error, + ): Promise { const date = new Date(); const fileName = `${filePrefix}_${getMonthDate(date)}.jsonl`; const file = path.join(this.dirPath, fileName); - const historyItem: CommandHistoryItem = { + const historyItem: CommandHistoryEntry = { date: getDayDate(date), cursorlessVersion: this.cursorlessVersion, + thrownError: thrownError?.name, command: sanitizeCommand(command), }; const data = JSON.stringify(historyItem) + "\n";