Skip to content

Commit

Permalink
Added thrown error
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Dec 12, 2023
1 parent 3c7cab9 commit 02b1160
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
9 changes: 6 additions & 3 deletions packages/common/src/types/commandHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
21 changes: 16 additions & 5 deletions packages/cursorless-vscode/src/CommandHistory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ActionDescriptor,
CommandComplete,
CommandHistoryItem,
CommandHistoryEntry,
Disposable,
FileSystem,
ReadOnlyHatMap,
Expand Down Expand Up @@ -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<void> {
private async appendToLog(
command: CommandComplete,
thrownError?: Error,
): Promise<void> {
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";
Expand Down

0 comments on commit 02b1160

Please sign in to comment.