@visulima/fs
Version:
Human friendly file system utilities for Node.js
46 lines (45 loc) • 1.5 kB
TypeScript
/**
* 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);
get name(): string;
set name(_name: string);
}
export default PermissionError;