| 1 | /** |
| 2 | * Recursively retrieves the root cause of an error by traversing through its `cause` property. |
| 3 | * |
| 4 | * @param err - The error object to analyze. It can be of any type. |
| 5 | * @returns The root cause of the error, or the original error if no further cause is found. |
| 6 | */ |
| 7 | export function getRootCause(err: any): any { |
| 8 | if (err.cause) { |
| 9 | return getRootCause(err.cause); |
| 10 | } |
| 11 | return err; |
| 12 | } |
| 13 | |
| 14 | export class ContinueError extends Error { |
| 15 | reason: ContinueErrorReason; |
| 16 | |
| 17 | constructor(reason: ContinueErrorReason, message?: string) { |
| 18 | super(message); |
| 19 | this.reason = reason; |
| 20 | this.name = "ContinueError"; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | export enum ContinueErrorReason { |
| 25 | // Find and Replace validation errors |
| 26 | FindAndReplaceIdenticalOldAndNewStrings = "find_and_replace_identical_old_and_new_strings", |
| 27 | FindAndReplaceMissingOldString = "find_and_replace_missing_old_string", |
| 28 | FindAndReplaceNonFirstEmptyOldString = "find_and_replace_non_first_empty_old_string", |
| 29 | FindAndReplaceMissingNewString = "find_and_replace_missing_new_string", |
| 30 | FindAndReplaceOldStringNotFound = "find_and_replace_old_string_not_found", |
| 31 | FindAndReplaceMultipleOccurrences = "find_and_replace_multiple_occurrences", |
| 32 | FindAndReplaceMissingFilepath = "find_and_replace_missing_filepath", |
| 33 | |
| 34 | // Multi-edit |
| 35 | MultiEditEditsArrayRequired = "multi_edit_edits_array_required", |
| 36 | MultiEditEditsArrayEmpty = "multi_edit_edits_array_empty", |
| 37 | MultiEditSubsequentEditsOnCreation = "multi_edit_subsequent_edits_on_creation", |
| 38 | MultiEditEmptyOldStringNotFirst = "multi_edit_empty_old_string_not_first", |
| 39 | |
| 40 | // General Edit |
| 41 | EditToolFileNotRead = "edit_tool_file_not_yet_read", |
| 42 | |
| 43 | // General File |
| 44 | FileAlreadyExists = "file_already_exists", |
| 45 | FileNotFound = "file_not_found", |
| 46 | FileWriteError = "file_write_error", |
| 47 | FileIsSecurityConcern = "file_is_security_concern", |
| 48 | ParentDirectoryNotFound = "parent_directory_not_found", |
| 49 | |
| 50 | // Other |
| 51 | Unspecified = "unspecified", |
| 52 | Unknown = "unknown", |
| 53 | } |