continue-custom/core/util/errors.ts

49 lines
1.8 KiB
TypeScript

/**
* Recursively retrieves the root cause of an error by traversing through its `cause` property.
*
* @param err - The error object to analyze. It can be of any type.
* @returns The root cause of the error, or the original error if no further cause is found.
*/
export function getRootCause(err: any): any {
if (err.cause) {
return getRootCause(err.cause);
}
return err;
}
export class ContinueError extends Error {
reason: ContinueErrorReason;
constructor(reason: ContinueErrorReason, message?: string) {
super(message);
this.reason = reason;
}
}
export enum ContinueErrorReason {
// Find and Replace validation errors
FindAndReplaceIdenticalStrings = "find_and_replace_old_and_new_strings_identical",
FindAndReplaceMissingOldString = "find_and_replace_missing_old_string",
FindAndReplaceMissingNewString = "find_and_replace_missing_new_string",
FindAndReplaceOldStringNotFound = "find_and_replace_old_string_not_found",
FindAndReplaceMultipleOccurrences = "find_and_replace_multiple_occurrences",
// File path errors
FindAndReplaceMissingFilepath = "find_and_replace_missing_filepath",
FindAndReplaceFileNotFound = "find_and_replace_file_not_found",
FindAndReplaceFileAlreadyExists = "find_and_replace_file_already_exists",
// Multi-edit specific errors
MultiEditEditsArrayRequired = "multi_edit_edits_array_required",
MultiEditEditsArrayEmpty = "multi_edit_edits_array_empty",
MultiEditSubsequentEditsOnCreation = "multi_edit_subsequent_edits_on_creation",
MultiEditEmptyOldStringNotFirst = "multi_edit_empty_old_string_not_first",
// CLI-specific errors
EditToolFileNotRead = "edit_tool_file_not_read",
CliParentDirectoryNotFound = "cli_parent_directory_not_found",
CliFileWriteError = "cli_file_write_error",
Unspecificied = "unspecified",
Unknown = "unknown",
}