ai-pp3
Version:
CLI tool combining multimodal AI analysis with RawTherapee's engine to generate optimized PP3 profiles for RAW photography
29 lines • 1.29 kB
JavaScript
import fs from "node:fs";
export async function validateFileAccess(filePath, mode) {
try {
await fs.promises.access(filePath, mode === "read" ? fs.constants.R_OK : fs.constants.W_OK);
}
catch (error) {
if (error instanceof Error && "code" in error) {
if (error.code === "ENOENT") {
throw new Error(`${mode === "read" ? "File" : "Directory"} not found: ${filePath}`);
}
else if (error.code === "EACCES") {
throw new Error(`Permission denied ${mode === "read" ? "reading" : "writing"} ${filePath}`);
}
}
throw new Error(`Error accessing ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
}
}
export function handleFileError(error, filePath, operation) {
if (error instanceof Error && "code" in error) {
if (error.code === "ENOENT") {
throw new Error(`File not found during ${operation}: ${filePath}`);
}
else if (error.code === "EACCES") {
throw new Error(`Permission denied ${operation}ing file: ${filePath}`);
}
}
throw new Error(`Error ${operation}ing file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
}
//# sourceMappingURL=validation.js.map