export { J as JSONError } from "./packem_shared/json-error.d-COL8oxF_.js"; /** * Error thrown when a file or directory already exists at a specified path, and an operation was expecting it not to. * @example * ```javascript * import { AlreadyExistsError } from "@visulima/fs/error"; // Assuming it's exported from an index or directly * import { ensureSymlinkSync } from "@visulima/fs"; // Or any function that might throw this * import { join } from "node:path"; * * try { * // Example: ensureSymlinkSync might throw this if a file (not a symlink) already exists at linkName * // For demonstration, let's assume someFunction internally throws it: * const someFunctionThatMightThrow = (path) => { * if (path === "/tmp/existing-file.txt") { // Simulate a check * throw new AlreadyExistsError(`file already exists at '/tmp/existing-file.txt'`); * } * } * someFunctionThatMightThrow("/tmp/existing-file.txt"); * } catch (error) { * if (error instanceof AlreadyExistsError) { * console.error(`Operation failed because path exists: ${error.message}`); * console.error(`Error code: ${error.code}`); // EEXIST * } else { * console.error("An unexpected error occurred:", error); * } * } * ``` */ declare class AlreadyExistsError extends Error { /** * Creates a new instance. * @param message */ constructor(message: string); get code(): string; set code(_name: string); override get name(): string; override set name(_name: string); } /** * Error thrown when an operation that is not allowed on a directory is attempted. * This typically occurs when a file-specific operation is used on a directory path. * @example * ```javascript * import { DirectoryError } from "@visulima/fs/error"; * import { readFile } from "@visulima/fs"; // Or any function that might throw this * import { join } from "node:path"; * * const attemptToReadFileFromDir = async () => { * try { * // Attempting to read a directory as if it were a file * // This is a conceptual example; readFile might throw a different error first * // depending on its internal checks, but EISDIR is the underlying system error. * // Forcing the scenario: * const pretendReadFileOnDir = (path) => { * if (path === "/tmp/my-directory") { // Simulate a directory path * throw new DirectoryError(`read '/tmp/my-directory'`); * } * } * pretendReadFileOnDir("/tmp/my-directory"); * // await readFile(join("/tmp", "my-directory")); * } catch (error) { * if (error instanceof DirectoryError) { * console.error(`Operation failed, path is a directory: ${error.message}`); * console.error(`Error code: ${error.code}`); // EISDIR * } else { * console.error("An unexpected error occurred:", error); * } * } * }; * * attemptToReadFileFromDir(); * ``` */ declare class DirectoryError extends Error { /** * Creates a new instance. * @param message */ constructor(message: string); get code(): string; set code(_name: string); override get name(): string; override set name(_name: string); } /** * Error thrown when a directory is not empty. * @example * ```javascript * import { NotEmptyError } from "@visulima/fs/error"; * import { rmdir } from "node:fs/promises"; // Or any fs function that might throw this system error * import { join } from "node:path"; * * const attemptToRemoveNonEmptyDir = async () => { * const dirPath = join("/tmp", "my-non-empty-dir"); // Assume this directory exists and has files * try { * // Forcing the scenario for demonstration, as rmdir might throw its own specific error. * // Node.js fs operations that encounter a non-empty directory when expecting an empty one * // typically throw an error with code ENOTEMPTY. * const simulateNotEmpty = (path) => { * if (path === dirPath) { // Simulate check for non-empty * throw new NotEmptyError(`rmdir '${dirPath}'`); * } * } * simulateNotEmpty(dirPath); * // await rmdir(dirPath); // This would likely throw an error with code ENOTEMPTY * } catch (error) { * if (error instanceof NotEmptyError) { * console.error(`Operation failed, directory is not empty: ${error.message}`); * console.error(`Error code: ${error.code}`); // ENOTEMPTY * } else { * console.error("An unexpected error occurred:", error); * } * } * }; * * // You would need to set up a non-empty directory at /tmp/my-non-empty-dir for a real test * // import { ensureDirSync, writeFileSync } from "@visulima/fs"; * // ensureDirSync(dirPath); * // writeFileSync(join(dirPath, "somefile.txt"), "content"); * * attemptToRemoveNonEmptyDir(); * ``` */ declare class NotEmptyError extends Error { /** * Creates a new instance. * @param message */ constructor(message: string); get code(): string; set code(_name: string); override get name(): string; override set name(_name: string); } /** * Error thrown when a file or directory is not found at a specified path. * @example * ```javascript * import { NotFoundError } from "@visulima/fs/error"; * import { readFile } from "@visulima/fs"; // Or any function that might throw this * import { join } from "node:path"; * * const tryReadingNonExistentFile = async () => { * const filePath = join("/tmp", "this-file-does-not-exist.txt"); * try { * // Forcing the scenario for demonstration, as readFile itself would throw this. * const simulateNotFound = (path) => { * if (path === filePath) { * throw new NotFoundError(`no such file or directory, open '${filePath}'`); * } * } * simulateNotFound(filePath); * // await readFile(filePath); * } catch (error) { * if (error instanceof NotFoundError) { * console.error(`Operation failed, path not found: ${error.message}`); * console.error(`Error code: ${error.code}`); // ENOENT * } else { * console.error("An unexpected error occurred:", error); * } * } * }; * * tryReadingNonExistentFile(); * ``` */ declare class NotFoundError extends Error { /** * Creates a new instance. * @param message */ constructor(message: string); get code(): string; set code(_name: string); override get name(): string; override set name(_name: string); } /** * Error thrown when an operation is not permitted due to insufficient privileges * or other access control restrictions. * @example * ```javascript * import { PermissionError } from "@visulima/fs/error"; * import { writeFile } from "@visulima/fs"; // Or any function that might throw this * import { join } from "node:path"; * * const tryWritingToProtectedFile = async () => { * const filePath = join("/root", "protected-file.txt"); // A path that typically requires root privileges * try { * // Forcing the scenario for demonstration, as writeFile itself would throw this. * const simulatePermissionError = (path) => { * if (path === filePath) { * throw new PermissionError(`open '${filePath}'`); * } * } * simulatePermissionError(filePath); * // await writeFile(filePath, "test content"); * } catch (error) { * if (error instanceof PermissionError) { * console.error(`Operation not permitted: ${error.message}`); * console.error(`Error code: ${error.code}`); // EPERM * } else { * console.error("An unexpected error occurred:", error); * } * } * }; * * tryWritingToProtectedFile(); * ``` */ declare class PermissionError extends Error { /** * Creates a new instance. * @param message */ constructor(message: string); get code(): string; set code(_name: string); override get name(): string; override set name(_name: string); } /** * Error thrown in walk or walkSync during iteration. * @example * ```javascript * import { WalkError } from "@visulima/fs/error"; * import { walk } from "@visulima/fs"; * import { join } from "node:path"; * * const processDirectory = async () => { * const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir"); * try { * // Forcing the scenario: walk might throw a WalkError if it encounters an issue * // like a directory it cannot read during the walk process. * const simulateWalkError = async (rootDir) => { * // Let's say readdir inside walk fails for a subdirectory. * const underlyingError = new Error("Permission denied reading subdirectory"); * throw new WalkError(underlyingError, rootDir); * } * // This is conceptual. In a real scenario, 'walk' itself would throw. * // for await (const entry of walk(dirToWalk)) { * // console.log(entry.path); * // } * await simulateWalkError(dirToWalk); * } catch (error) { * if (error instanceof WalkError) { * console.error(`Error during directory walk of "${error.root}": ${error.message}`); * if (error.cause) { * console.error(`Underlying cause: ${error.cause}`); * } * } else { * console.error("An unexpected error occurred:", error); * } * } * }; * * processDirectory(); * ``` */ declare class WalkError extends Error { /** File path of the root that's being walked. */ root: string; /** * Constructs a new instance. * @param cause The underlying error or reason for the walk failure. * @param root The root directory path where the walk operation started or encountered the error. */ constructor(cause: unknown, root: string); override get name(): string; override set name(_name: string); } export { AlreadyExistsError, DirectoryError, NotEmptyError, NotFoundError, PermissionError, WalkError };