knowhub
Version:
Synchronize AI coding–agent knowledge files (rules, templates, guidelines) across your project.
68 lines • 2.11 kB
JavaScript
export class KnowhubError extends Error {
code;
constructor(message, code) {
super(message);
this.code = code;
this.name = "KnowhubError";
}
}
export class ConfigurationError extends KnowhubError {
configPath;
constructor(message, configPath) {
super(message);
this.configPath = configPath;
this.name = "ConfigurationError";
this.code = "CONFIG_ERROR";
}
}
export class ResourceError extends KnowhubError {
resourcePath;
constructor(message, resourcePath) {
super(message);
this.resourcePath = resourcePath;
this.name = "ResourceError";
this.code = "RESOURCE_ERROR";
}
}
export class ValidationError extends KnowhubError {
field;
constructor(message, field) {
super(message);
this.field = field;
this.name = "ValidationError";
this.code = "VALIDATION_ERROR";
}
}
export class FileOperationError extends KnowhubError {
filePath;
operation;
constructor(message, filePath, operation) {
super(message);
this.filePath = filePath;
this.operation = operation;
this.name = "FileOperationError";
this.code = "FILE_ERROR";
}
}
export function formatError(error) {
if (error instanceof Error) {
return error.message;
}
return String(error);
}
export function handleNodeError(error, path, operation) {
const nodeError = error;
switch (nodeError.code) {
case "ENOENT":
throw new FileOperationError(`Path does not exist: ${path}`, path, operation);
case "EACCES":
throw new FileOperationError(`No permission to access path: ${path}`, path, operation);
case "EPERM":
throw new FileOperationError(`Operation not permitted: ${path}`, path, operation);
default: {
const message = error instanceof Error ? error.message : String(error);
throw new FileOperationError(`${operation} failed for "${path}": ${message}`, path, operation);
}
}
}
//# sourceMappingURL=errors.js.map