UNPKG

node-os-utils

Version:

Advanced cross-platform operating system monitoring utilities with TypeScript support

67 lines 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MonitorError = exports.ErrorCode = void 0; /** * 错误代码枚举 */ var ErrorCode; (function (ErrorCode) { ErrorCode["PLATFORM_NOT_SUPPORTED"] = "PLATFORM_NOT_SUPPORTED"; ErrorCode["COMMAND_FAILED"] = "COMMAND_FAILED"; ErrorCode["PARSE_ERROR"] = "PARSE_ERROR"; ErrorCode["PERMISSION_DENIED"] = "PERMISSION_DENIED"; ErrorCode["TIMEOUT"] = "TIMEOUT"; ErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG"; ErrorCode["NOT_AVAILABLE"] = "NOT_AVAILABLE"; ErrorCode["FILE_NOT_FOUND"] = "FILE_NOT_FOUND"; ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR"; // 网络操作失败 })(ErrorCode || (exports.ErrorCode = ErrorCode = {})); /** * 监控错误类 */ class MonitorError extends Error { constructor(message, code, platform, details) { super(message); this.code = code; this.platform = platform; this.details = details; this.name = 'MonitorError'; // 确保堆栈跟踪正确显示 if (Error.captureStackTrace) { Error.captureStackTrace(this, MonitorError); } } /** * 转换为 JSON 对象 */ toJSON() { return { name: this.name, message: this.message, code: this.code, platform: this.platform, details: this.details, stack: this.stack }; } /** * 创建平台不支持错误 */ static createPlatformNotSupported(platform, feature) { return new MonitorError(`Feature '${feature}' is not supported on platform '${platform}'`, ErrorCode.PLATFORM_NOT_SUPPORTED, platform, { feature }); } /** * 创建命令执行失败错误 */ static createCommandFailed(platform, command, details) { return new MonitorError(`Command execution failed: ${command}`, ErrorCode.COMMAND_FAILED, platform, { command, ...details }); } /** * 创建解析错误 */ static createParseError(platform, data, reason) { return new MonitorError(`Failed to parse data: ${reason || 'Unknown parsing error'}`, ErrorCode.PARSE_ERROR, platform, { data: data.substring(0, 100) + (data.length > 100 ? '...' : ''), reason }); } } exports.MonitorError = MonitorError; //# sourceMappingURL=errors.js.map