scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
77 lines • 3.61 kB
JavaScript
const FILE_MANAGER_ERROR_CODES = {
NOT_FOUND: "NOT_FOUND",
INVALID_PATH: "INVALID_PATH",
PERMISSION_DENIED: "PERMISSION_DENIED",
ACCESS_DENIED: "ACCESS_DENIED",
ALREADY_EXISTS: "ALREADY_EXISTS",
NOT_A_FILE: "NOT_A_FILE",
NOT_A_DIRECTORY: "NOT_A_DIRECTORY",
DIRECTORY_NOT_EMPTY: "DIRECTORY_NOT_EMPTY",
OUTSIDE_ROOT: "OUTSIDE_ROOT",
IO_ERROR: "IO_ERROR",
LOCK_ERROR: "LOCK_ERROR",
INVALID_OPERATION: "INVALID_OPERATION",
EXTENDED_ATTRIBUTE_NOT_FOUND: "EXTENDED_ATTRIBUTE_NOT_FOUND",
TAG_NOT_FOUND: "TAG_NOT_FOUND",
FILE_NOT_FOUND: "FILE_NOT_FOUND",
PARENT_DIRECTORY_NOT_FOUND: "PARENT_DIRECTORY_NOT_FOUND",
UNKNOWN: "UNKNOWN"
};
const FILE_MANAGER_ERROR_MESSAGES = {
[]: "File or directory not found: {path}",
[]: "Invalid path: {path}",
[]: "Permission denied: {path}",
[]: "Access denied: {path}",
[]: "File or directory already exists: {path}",
[]: "Path is not a file: {path}",
[]: "Path is not a directory: {path}",
[]: "Directory not empty: {path}",
[]: "Path is outside the root directory",
[]: "IO error: {message}",
[]: "Lock error: {message}",
[]: "Invalid operation: {message}",
[]: "Extended attribute not found",
[]: "Tag not found",
[]: "File not found",
[]: "Parent directory does not exist",
[]: "Unknown error"
};
class FileManagerError extends Error {
constructor(message, code, path, originalError) {
let formattedMessage = message;
if (message.includes("{message}") && originalError) {
formattedMessage = formattedMessage.replace("{message}", originalError.message);
} else if (message.includes("{message}")) {
formattedMessage = formattedMessage.replace(": {message}", "");
}
if (path) {
formattedMessage = formattedMessage.replace("{path}", path);
}
const fullMessage = path ? `${formattedMessage} (Path: ${path})` : formattedMessage;
super(fullMessage);
this.code = code;
this.path = path;
this.originalError = originalError;
this.name = "FileManagerError";
}
toString() {
return `${this.name}: ${this.message}`;
}
}
const ERROR_MESSAGES = {
FILE_NOT_FOUND: FILE_MANAGER_ERROR_MESSAGES[FILE_MANAGER_ERROR_CODES.FILE_NOT_FOUND],
DIRECTORY_NOT_FOUND: FILE_MANAGER_ERROR_MESSAGES[FILE_MANAGER_ERROR_CODES.NOT_FOUND],
OUTSIDE_ROOT: FILE_MANAGER_ERROR_MESSAGES[FILE_MANAGER_ERROR_CODES.OUTSIDE_ROOT],
INVALID_PATH: FILE_MANAGER_ERROR_MESSAGES[FILE_MANAGER_ERROR_CODES.INVALID_PATH],
NOT_A_FILE: FILE_MANAGER_ERROR_MESSAGES[FILE_MANAGER_ERROR_CODES.NOT_A_FILE],
NOT_A_DIRECTORY: FILE_MANAGER_ERROR_MESSAGES[FILE_MANAGER_ERROR_CODES.NOT_A_DIRECTORY],
ALREADY_EXISTS: FILE_MANAGER_ERROR_MESSAGES[FILE_MANAGER_ERROR_CODES.ALREADY_EXISTS],
ACCESS_DENIED: FILE_MANAGER_ERROR_MESSAGES[FILE_MANAGER_ERROR_CODES.ACCESS_DENIED]
};
export {
ERROR_MESSAGES,
FILE_MANAGER_ERROR_CODES,
FILE_MANAGER_ERROR_MESSAGES,
FileManagerError
};
//# sourceMappingURL=errors.js.map