UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

40 lines (39 loc) 1.48 kB
/** * 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); get name(): string; set name(_name: string); } export default AlreadyExistsError;