scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
103 lines • 4.79 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var errors_exports = {};
__export(errors_exports, {
ERROR_MESSAGES: () => ERROR_MESSAGES,
FILE_MANAGER_ERROR_CODES: () => FILE_MANAGER_ERROR_CODES,
FILE_MANAGER_ERROR_MESSAGES: () => FILE_MANAGER_ERROR_MESSAGES,
FileManagerError: () => FileManagerError
});
module.exports = __toCommonJS(errors_exports);
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_MANAGER_ERROR_CODES.NOT_FOUND]: "File or directory not found: {path}",
[FILE_MANAGER_ERROR_CODES.INVALID_PATH]: "Invalid path: {path}",
[FILE_MANAGER_ERROR_CODES.PERMISSION_DENIED]: "Permission denied: {path}",
[FILE_MANAGER_ERROR_CODES.ACCESS_DENIED]: "Access denied: {path}",
[FILE_MANAGER_ERROR_CODES.ALREADY_EXISTS]: "File or directory already exists: {path}",
[FILE_MANAGER_ERROR_CODES.NOT_A_FILE]: "Path is not a file: {path}",
[FILE_MANAGER_ERROR_CODES.NOT_A_DIRECTORY]: "Path is not a directory: {path}",
[FILE_MANAGER_ERROR_CODES.DIRECTORY_NOT_EMPTY]: "Directory not empty: {path}",
[FILE_MANAGER_ERROR_CODES.OUTSIDE_ROOT]: "Path is outside the root directory",
[FILE_MANAGER_ERROR_CODES.IO_ERROR]: "IO error: {message}",
[FILE_MANAGER_ERROR_CODES.LOCK_ERROR]: "Lock error: {message}",
[FILE_MANAGER_ERROR_CODES.INVALID_OPERATION]: "Invalid operation: {message}",
[FILE_MANAGER_ERROR_CODES.EXTENDED_ATTRIBUTE_NOT_FOUND]: "Extended attribute not found",
[FILE_MANAGER_ERROR_CODES.TAG_NOT_FOUND]: "Tag not found",
[FILE_MANAGER_ERROR_CODES.FILE_NOT_FOUND]: "File not found",
[FILE_MANAGER_ERROR_CODES.PARENT_DIRECTORY_NOT_FOUND]: "Parent directory does not exist",
[FILE_MANAGER_ERROR_CODES.UNKNOWN]: "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]
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ERROR_MESSAGES,
FILE_MANAGER_ERROR_CODES,
FILE_MANAGER_ERROR_MESSAGES,
FileManagerError
});
//# sourceMappingURL=errors.js.map