mcp-ai-agent-guidelines
Version:
A comprehensive Model Context Protocol server providing advanced tools, resources, and prompts for implementing AI agent best practices
90 lines • 4.41 kB
JavaScript
/**
* Centralized error codes following numbering convention:
* - 1xxx: Validation Errors
* - 2xxx: Domain Errors
* - 3xxx: Session Errors
* - 4xxx: External Errors
* - 5xxx: Configuration Errors
* - 9xxx: Internal Errors
*/
export var ErrorCode;
(function (ErrorCode) {
// 1xxx: Validation Errors
ErrorCode[ErrorCode["VALIDATION_FAILED"] = 1000] = "VALIDATION_FAILED";
ErrorCode[ErrorCode["MISSING_REQUIRED_FIELD"] = 1001] = "MISSING_REQUIRED_FIELD";
ErrorCode[ErrorCode["INVALID_FORMAT"] = 1002] = "INVALID_FORMAT";
ErrorCode[ErrorCode["SCHEMA_VIOLATION"] = 1003] = "SCHEMA_VIOLATION";
ErrorCode[ErrorCode["OUT_OF_RANGE"] = 1004] = "OUT_OF_RANGE";
ErrorCode[ErrorCode["INVALID_PARAMETER"] = 1005] = "INVALID_PARAMETER";
// 2xxx: Domain Errors
ErrorCode[ErrorCode["DOMAIN_ERROR"] = 2000] = "DOMAIN_ERROR";
ErrorCode[ErrorCode["INVALID_STATE"] = 2001] = "INVALID_STATE";
ErrorCode[ErrorCode["CONSTRAINT_VIOLATION"] = 2002] = "CONSTRAINT_VIOLATION";
ErrorCode[ErrorCode["BUSINESS_RULE_VIOLATION"] = 2003] = "BUSINESS_RULE_VIOLATION";
// 3xxx: Session Errors
ErrorCode[ErrorCode["SESSION_NOT_FOUND"] = 3000] = "SESSION_NOT_FOUND";
ErrorCode[ErrorCode["SESSION_EXPIRED"] = 3001] = "SESSION_EXPIRED";
ErrorCode[ErrorCode["INVALID_PHASE_TRANSITION"] = 3002] = "INVALID_PHASE_TRANSITION";
ErrorCode[ErrorCode["COVERAGE_NOT_MET"] = 3003] = "COVERAGE_NOT_MET";
// 4xxx: External Errors
ErrorCode[ErrorCode["FILE_NOT_FOUND"] = 4000] = "FILE_NOT_FOUND";
ErrorCode[ErrorCode["FILE_READ_ERROR"] = 4001] = "FILE_READ_ERROR";
ErrorCode[ErrorCode["FILE_WRITE_ERROR"] = 4002] = "FILE_WRITE_ERROR";
ErrorCode[ErrorCode["NETWORK_ERROR"] = 4003] = "NETWORK_ERROR";
ErrorCode[ErrorCode["RESOURCE_NOT_FOUND"] = 4004] = "RESOURCE_NOT_FOUND";
// 5xxx: Configuration Errors
ErrorCode[ErrorCode["CONFIG_NOT_FOUND"] = 5000] = "CONFIG_NOT_FOUND";
ErrorCode[ErrorCode["CONFIG_INVALID"] = 5001] = "CONFIG_INVALID";
ErrorCode[ErrorCode["MISSING_DEPENDENCY"] = 5002] = "MISSING_DEPENDENCY";
// 9xxx: Internal Errors
ErrorCode[ErrorCode["INTERNAL_ERROR"] = 9000] = "INTERNAL_ERROR";
ErrorCode[ErrorCode["NOT_IMPLEMENTED"] = 9001] = "NOT_IMPLEMENTED";
ErrorCode[ErrorCode["UNEXPECTED_STATE"] = 9002] = "UNEXPECTED_STATE";
})(ErrorCode || (ErrorCode = {}));
/**
* Human-readable error messages for each error code
*/
export const ERROR_MESSAGES = {
// 1xxx: Validation Errors
[]: "Validation failed",
[]: "Required field is missing",
[]: "Invalid format",
[]: "Schema violation",
[]: "Value is out of range",
[]: "Invalid parameter",
// 2xxx: Domain Errors
[]: "Domain error",
[]: "Invalid state",
[]: "Constraint violation",
[]: "Business rule violation",
// 3xxx: Session Errors
[]: "Session not found",
[]: "Session has expired",
[]: "Invalid phase transition",
[]: "Coverage threshold not met",
// 4xxx: External Errors
[]: "File not found",
[]: "File read error",
[]: "File write error",
[]: "Network error",
[]: "Resource not found",
// 5xxx: Configuration Errors
[]: "Configuration not found",
[]: "Configuration is invalid",
[]: "Missing dependency",
// 9xxx: Internal Errors
[]: "Internal error",
[]: "Not implemented",
[]: "Unexpected state",
};
/**
* Determines if an error code represents a retryable error.
* Only external errors (4xxx) are considered retryable as they may be transient.
*
* @param code - The error code to check
* @returns true if the error is retryable, false otherwise
*/
export function isRetryable(code) {
return code >= 4000 && code < 5000;
}
//# sourceMappingURL=error-codes.js.map