shellx-ai 1.0.12 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +586 -0
- package/dist/automation/element-finder.d.ts +189 -0
- package/dist/automation/element-finder.js +322 -0
- package/dist/automation/element-finder.js.map +1 -0
- package/dist/automation/ui-action-handler.d.ts +330 -0
- package/dist/automation/ui-action-handler.js +873 -0
- package/dist/automation/ui-action-handler.js.map +1 -0
- package/dist/cbor-compat.d.ts +27 -0
- package/dist/cbor-compat.js +108 -0
- package/dist/cbor-compat.js.map +1 -0
- package/dist/domain-manager.d.ts +80 -0
- package/dist/domain-manager.js +158 -0
- package/dist/domain-manager.js.map +1 -0
- package/dist/error-handler.d.ts +87 -0
- package/dist/error-handler.js +148 -0
- package/dist/error-handler.js.map +1 -0
- package/dist/errors.d.ts +114 -0
- package/dist/errors.js +139 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +163 -54
- package/dist/index.js +706 -480
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +81 -0
- package/dist/logger.js +128 -0
- package/dist/logger.js.map +1 -0
- package/dist/protocol.d.ts +147 -31
- package/dist/protocol.js +2 -2
- package/dist/protocol.js.map +1 -0
- package/dist/shell/output-buffer.d.ts +152 -0
- package/dist/shell/output-buffer.js +163 -0
- package/dist/shell/output-buffer.js.map +1 -0
- package/dist/shell/shell-command-executor.d.ts +182 -0
- package/dist/shell/shell-command-executor.js +348 -0
- package/dist/shell/shell-command-executor.js.map +1 -0
- package/dist/shellx.d.ts +681 -178
- package/dist/shellx.js +762 -1159
- package/dist/shellx.js.map +1 -0
- package/dist/types.d.ts +132 -57
- package/dist/types.js +4 -4
- package/dist/types.js.map +1 -0
- package/dist/utils/retry-helper.d.ts +73 -0
- package/dist/utils/retry-helper.js +92 -0
- package/dist/utils/retry-helper.js.map +1 -0
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +17 -23
- package/dist/utils.js.map +1 -0
- package/package.json +95 -62
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ErrorHandler - Unified error handling utilities for ShellX
|
|
3
|
+
*
|
|
4
|
+
* This module provides consistent error handling patterns across the codebase,
|
|
5
|
+
* ensuring all errors are properly formatted, logged, and returned.
|
|
6
|
+
*/
|
|
7
|
+
import { OperationError, ValidationError } from "./errors.js";
|
|
8
|
+
/**
|
|
9
|
+
* Safely extracts error message from unknown error
|
|
10
|
+
* @param error - Unknown error object
|
|
11
|
+
* @param defaultMessage - Default message if extraction fails
|
|
12
|
+
* @returns Error message string
|
|
13
|
+
*/
|
|
14
|
+
export function extractErrorMessage(error, defaultMessage = "Unknown error occurred") {
|
|
15
|
+
if (error instanceof Error) {
|
|
16
|
+
return error.message;
|
|
17
|
+
}
|
|
18
|
+
if (typeof error === "string") {
|
|
19
|
+
return error;
|
|
20
|
+
}
|
|
21
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
22
|
+
return String(error.message);
|
|
23
|
+
}
|
|
24
|
+
return defaultMessage;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a standardized error result
|
|
28
|
+
* @param error - Error object or message
|
|
29
|
+
* @param startTime - Operation start time for duration calculation
|
|
30
|
+
* @param options - Error handler options
|
|
31
|
+
* @returns Standardized error result
|
|
32
|
+
*/
|
|
33
|
+
export function createErrorResult(error, startTime, options = {}) {
|
|
34
|
+
const errorMessage = extractErrorMessage(error, options.defaultErrorMessage);
|
|
35
|
+
if (options.logError !== false && options.logPrefix) {
|
|
36
|
+
console.error(`${options.logPrefix}`, error);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
error: errorMessage,
|
|
41
|
+
duration: Date.now() - startTime,
|
|
42
|
+
timestamp: startTime,
|
|
43
|
+
...options.context,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a standardized success result
|
|
48
|
+
* @param data - Success data
|
|
49
|
+
* @param startTime - Operation start time
|
|
50
|
+
* @returns Standardized success result
|
|
51
|
+
*/
|
|
52
|
+
export function createSuccessResult(data, startTime) {
|
|
53
|
+
return {
|
|
54
|
+
success: true,
|
|
55
|
+
duration: Date.now() - startTime,
|
|
56
|
+
timestamp: startTime,
|
|
57
|
+
...data,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Wraps an async operation with standardized error handling
|
|
62
|
+
* @param operation - Async operation to execute
|
|
63
|
+
* @param startTime - Operation start time
|
|
64
|
+
* @param options - Error handler options
|
|
65
|
+
* @returns Promise resolving to result or error
|
|
66
|
+
*/
|
|
67
|
+
export async function handleOperation(operation, startTime, options = {}) {
|
|
68
|
+
try {
|
|
69
|
+
const data = await operation();
|
|
70
|
+
return createSuccessResult(data, startTime);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw new OperationError(extractErrorMessage(error, options.defaultErrorMessage), options.context);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Validates required parameters and throws ValidationError if missing
|
|
78
|
+
* @param params - Parameters to validate
|
|
79
|
+
* @param paramName - Name of the parameter for error message
|
|
80
|
+
* @throws ValidationError if parameter is missing/invalid
|
|
81
|
+
*/
|
|
82
|
+
export function validateRequired(param, paramName) {
|
|
83
|
+
if (param === undefined || param === null) {
|
|
84
|
+
throw new ValidationError(`Required parameter '${paramName}' is missing`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Validates one of multiple required parameters is present
|
|
89
|
+
* @param params - Object with parameters to validate
|
|
90
|
+
* @param requiredNames - Array of parameter names (at least one must be present)
|
|
91
|
+
* @throws ValidationError if none of the parameters are present
|
|
92
|
+
*/
|
|
93
|
+
export function validateOneOfRequired(params, requiredNames) {
|
|
94
|
+
const hasOne = requiredNames.some((name) => params[name] !== undefined && params[name] !== null);
|
|
95
|
+
if (!hasOne) {
|
|
96
|
+
throw new ValidationError(`At least one of the following parameters is required: ${requiredNames.join(", ")}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Executes operation with retry and standardized error handling
|
|
101
|
+
* @param operation - Async operation to execute
|
|
102
|
+
* @param startTime - Operation start time
|
|
103
|
+
* @param options - Error handler options
|
|
104
|
+
* @returns Promise resolving to result or null if all retries fail
|
|
105
|
+
*/
|
|
106
|
+
export async function handleOperationWithRetry(operation, startTime, options = {}) {
|
|
107
|
+
const { maxRetries = 3, retryDelay = 500, ...errorOptions } = options;
|
|
108
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
109
|
+
try {
|
|
110
|
+
const data = await operation();
|
|
111
|
+
return createSuccessResult(data, startTime);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
const isLastAttempt = attempt === maxRetries;
|
|
115
|
+
if (errorOptions.logError !== false) {
|
|
116
|
+
console.warn(`${errorOptions.logPrefix || "Operation"} attempt ${attempt}/${maxRetries} failed:`, error);
|
|
117
|
+
}
|
|
118
|
+
if (isLastAttempt) {
|
|
119
|
+
return createErrorResult(error, startTime, {
|
|
120
|
+
...errorOptions,
|
|
121
|
+
defaultErrorMessage: errorOptions.defaultErrorMessage || "Operation failed after retries",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// Wait before retry
|
|
125
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// This should never be reached, but TypeScript needs it
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Wraps an error with additional context for better debugging
|
|
133
|
+
* @param error - Original error
|
|
134
|
+
* @param context - Additional context information
|
|
135
|
+
* @param operationName - Name of the operation that failed
|
|
136
|
+
* @returns Wrapped error with context
|
|
137
|
+
*/
|
|
138
|
+
export function wrapErrorWithContext(error, context, operationName) {
|
|
139
|
+
const baseMessage = extractErrorMessage(error);
|
|
140
|
+
const contextStr = Object.entries(context)
|
|
141
|
+
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
|
|
142
|
+
.join(", ");
|
|
143
|
+
const message = `${operationName} failed: ${baseMessage}${contextStr ? ` (${contextStr})` : ""}`;
|
|
144
|
+
const wrappedError = new Error(message);
|
|
145
|
+
wrappedError.stack = error instanceof Error ? error.stack : undefined;
|
|
146
|
+
return wrappedError;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAqB9D;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,iBAAyB,wBAAwB;IAEjD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QAC7D,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAc,EACd,SAAiB,EACjB,UAA+B,EAAE;IAEjC,MAAM,YAAY,GAAG,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAE7E,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACpD,OAAO,CAAC,KAAK,CAAC,GA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,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc,EACd,OAAgC,EAChC,aAAqB;IAErB,MAAM,WAAW,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SACvC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;SACxD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,OAAO,GAAG,GAAG,aAAa,YAAY,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAEjG,MAAM,YAAY,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IACxC,YAAY,CAAC,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAEtE,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Error Handling Types for ShellX
|
|
3
|
+
*
|
|
4
|
+
* This module defines consistent error response structures used across
|
|
5
|
+
* the entire ShellX codebase to ensure error handling is uniform.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Standard error response structure
|
|
9
|
+
* All error responses should follow this format
|
|
10
|
+
*/
|
|
11
|
+
export interface ErrorResponse {
|
|
12
|
+
/** Error message describing what went wrong */
|
|
13
|
+
error: string;
|
|
14
|
+
/** Optional error code for categorization */
|
|
15
|
+
code?: string;
|
|
16
|
+
/** Additional error details */
|
|
17
|
+
details?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Standard operation result with error information
|
|
21
|
+
* This is the base interface for all operation results
|
|
22
|
+
*/
|
|
23
|
+
export interface BaseOperationResult {
|
|
24
|
+
/** Whether the operation completed successfully */
|
|
25
|
+
success: boolean;
|
|
26
|
+
/** Error information if operation failed */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** Time taken for the operation in milliseconds */
|
|
29
|
+
duration: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a standardized error response
|
|
33
|
+
* @param message - Error message
|
|
34
|
+
* @param code - Optional error code
|
|
35
|
+
* @param details - Optional additional details
|
|
36
|
+
* @returns Standardized error response
|
|
37
|
+
*/
|
|
38
|
+
export declare function createErrorResponse(message: string, code?: string, details?: Record<string, unknown>): ErrorResponse;
|
|
39
|
+
/**
|
|
40
|
+
* Create a standardized operation result
|
|
41
|
+
* @param success - Whether operation succeeded
|
|
42
|
+
* @param duration - Operation duration in milliseconds
|
|
43
|
+
* @param error - Optional error message
|
|
44
|
+
* @returns Standardized operation result
|
|
45
|
+
*/
|
|
46
|
+
export declare function createOperationResult(success: boolean, duration: number, error?: string): BaseOperationResult;
|
|
47
|
+
/**
|
|
48
|
+
* Standard error codes
|
|
49
|
+
*/
|
|
50
|
+
export declare enum ErrorCode {
|
|
51
|
+
CONNECTION_FAILED = "CONNECTION_FAILED",
|
|
52
|
+
CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT",
|
|
53
|
+
AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED",
|
|
54
|
+
DEVICE_NOT_FOUND = "DEVICE_NOT_FOUND",
|
|
55
|
+
DEVICE_NOT_REGISTERED = "DEVICE_NOT_REGISTERED",
|
|
56
|
+
OPERATION_FAILED = "OPERATION_FAILED",
|
|
57
|
+
OPERATION_TIMEOUT = "OPERATION_TIMEOUT",
|
|
58
|
+
OPERATION_CANCELLED = "OPERATION_CANCELLED",
|
|
59
|
+
ELEMENT_NOT_FOUND = "ELEMENT_NOT_FOUND",
|
|
60
|
+
ELEMENT_NOT_VISIBLE = "ELEMENT_NOT_VISIBLE",
|
|
61
|
+
ELEMENT_NOT_CLICKABLE = "ELEMENT_NOT_CLICKABLE",
|
|
62
|
+
INVALID_SELECTOR = "INVALID_SELECTOR",
|
|
63
|
+
INVALID_INPUT = "INVALID_INPUT",
|
|
64
|
+
MISSING_PARAMETER = "MISSING_PARAMETER",
|
|
65
|
+
INVALID_FORMAT = "INVALID_FORMAT",
|
|
66
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
67
|
+
NOT_INITIALIZED = "NOT_INITIALIZED",
|
|
68
|
+
NOT_SUPPORTED = "NOT_SUPPORTED",
|
|
69
|
+
COMMAND_FAILED = "COMMAND_FAILED",
|
|
70
|
+
COMMAND_TIMEOUT = "COMMAND_TIMEOUT",
|
|
71
|
+
COMMAND_EXIT_CODE = "COMMAND_EXIT_CODE"
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* ShellX specific error class
|
|
75
|
+
*/
|
|
76
|
+
export declare class ShellXError extends Error {
|
|
77
|
+
/** Error code for categorization */
|
|
78
|
+
readonly code: string;
|
|
79
|
+
/** Additional error details */
|
|
80
|
+
readonly details?: Record<string, unknown>;
|
|
81
|
+
constructor(message: string, code: string, details?: Record<string, unknown>);
|
|
82
|
+
/**
|
|
83
|
+
* Convert error to standardized response format
|
|
84
|
+
*/
|
|
85
|
+
toResponse(): ErrorResponse;
|
|
86
|
+
/**
|
|
87
|
+
* Create ShellXError from unknown error
|
|
88
|
+
*/
|
|
89
|
+
static fromUnknown(error: unknown, defaultCode?: ErrorCode): ShellXError;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Connection error class
|
|
93
|
+
*/
|
|
94
|
+
export declare class ConnectionError extends ShellXError {
|
|
95
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Operation error class
|
|
99
|
+
*/
|
|
100
|
+
export declare class OperationError extends ShellXError {
|
|
101
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Element error class
|
|
105
|
+
*/
|
|
106
|
+
export declare class ElementError extends ShellXError {
|
|
107
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Validation error class
|
|
111
|
+
*/
|
|
112
|
+
export declare class ValidationError extends ShellXError {
|
|
113
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
114
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Error Handling Types for ShellX
|
|
3
|
+
*
|
|
4
|
+
* This module defines consistent error response structures used across
|
|
5
|
+
* the entire ShellX codebase to ensure error handling is uniform.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create a standardized error response
|
|
9
|
+
* @param message - Error message
|
|
10
|
+
* @param code - Optional error code
|
|
11
|
+
* @param details - Optional additional details
|
|
12
|
+
* @returns Standardized error response
|
|
13
|
+
*/
|
|
14
|
+
export function createErrorResponse(message, code, details) {
|
|
15
|
+
const response = { error: message };
|
|
16
|
+
if (code)
|
|
17
|
+
response.code = code;
|
|
18
|
+
if (details)
|
|
19
|
+
response.details = details;
|
|
20
|
+
return response;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a standardized operation result
|
|
24
|
+
* @param success - Whether operation succeeded
|
|
25
|
+
* @param duration - Operation duration in milliseconds
|
|
26
|
+
* @param error - Optional error message
|
|
27
|
+
* @returns Standardized operation result
|
|
28
|
+
*/
|
|
29
|
+
export function createOperationResult(success, duration, error) {
|
|
30
|
+
const result = { success, duration };
|
|
31
|
+
if (error)
|
|
32
|
+
result.error = error;
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Standard error codes
|
|
37
|
+
*/
|
|
38
|
+
export var ErrorCode;
|
|
39
|
+
(function (ErrorCode) {
|
|
40
|
+
// Connection errors (1xxx)
|
|
41
|
+
ErrorCode["CONNECTION_FAILED"] = "CONNECTION_FAILED";
|
|
42
|
+
ErrorCode["CONNECTION_TIMEOUT"] = "CONNECTION_TIMEOUT";
|
|
43
|
+
ErrorCode["AUTHENTICATION_FAILED"] = "AUTHENTICATION_FAILED";
|
|
44
|
+
ErrorCode["DEVICE_NOT_FOUND"] = "DEVICE_NOT_FOUND";
|
|
45
|
+
ErrorCode["DEVICE_NOT_REGISTERED"] = "DEVICE_NOT_REGISTERED";
|
|
46
|
+
// Operation errors (2xxx)
|
|
47
|
+
ErrorCode["OPERATION_FAILED"] = "OPERATION_FAILED";
|
|
48
|
+
ErrorCode["OPERATION_TIMEOUT"] = "OPERATION_TIMEOUT";
|
|
49
|
+
ErrorCode["OPERATION_CANCELLED"] = "OPERATION_CANCELLED";
|
|
50
|
+
// Element errors (3xxx)
|
|
51
|
+
ErrorCode["ELEMENT_NOT_FOUND"] = "ELEMENT_NOT_FOUND";
|
|
52
|
+
ErrorCode["ELEMENT_NOT_VISIBLE"] = "ELEMENT_NOT_VISIBLE";
|
|
53
|
+
ErrorCode["ELEMENT_NOT_CLICKABLE"] = "ELEMENT_NOT_CLICKABLE";
|
|
54
|
+
ErrorCode["INVALID_SELECTOR"] = "INVALID_SELECTOR";
|
|
55
|
+
// Input errors (4xxx)
|
|
56
|
+
ErrorCode["INVALID_INPUT"] = "INVALID_INPUT";
|
|
57
|
+
ErrorCode["MISSING_PARAMETER"] = "MISSING_PARAMETER";
|
|
58
|
+
ErrorCode["INVALID_FORMAT"] = "INVALID_FORMAT";
|
|
59
|
+
// System errors (5xxx)
|
|
60
|
+
ErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
61
|
+
ErrorCode["NOT_INITIALIZED"] = "NOT_INITIALIZED";
|
|
62
|
+
ErrorCode["NOT_SUPPORTED"] = "NOT_SUPPORTED";
|
|
63
|
+
// Command errors (6xxx)
|
|
64
|
+
ErrorCode["COMMAND_FAILED"] = "COMMAND_FAILED";
|
|
65
|
+
ErrorCode["COMMAND_TIMEOUT"] = "COMMAND_TIMEOUT";
|
|
66
|
+
ErrorCode["COMMAND_EXIT_CODE"] = "COMMAND_EXIT_CODE";
|
|
67
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
68
|
+
/**
|
|
69
|
+
* ShellX specific error class
|
|
70
|
+
*/
|
|
71
|
+
export class ShellXError extends Error {
|
|
72
|
+
/** Error code for categorization */
|
|
73
|
+
code;
|
|
74
|
+
/** Additional error details */
|
|
75
|
+
details;
|
|
76
|
+
constructor(message, code, details) {
|
|
77
|
+
super(message);
|
|
78
|
+
this.name = "ShellXError";
|
|
79
|
+
this.code = code;
|
|
80
|
+
this.details = details;
|
|
81
|
+
// Maintains proper stack trace for where our error was thrown
|
|
82
|
+
if (Error.captureStackTrace) {
|
|
83
|
+
Error.captureStackTrace(this, ShellXError);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Convert error to standardized response format
|
|
88
|
+
*/
|
|
89
|
+
toResponse() {
|
|
90
|
+
return createErrorResponse(this.message, this.code, this.details);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create ShellXError from unknown error
|
|
94
|
+
*/
|
|
95
|
+
static fromUnknown(error, defaultCode = ErrorCode.INTERNAL_ERROR) {
|
|
96
|
+
if (error instanceof ShellXError) {
|
|
97
|
+
return error;
|
|
98
|
+
}
|
|
99
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
100
|
+
return new ShellXError(message, defaultCode);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Connection error class
|
|
105
|
+
*/
|
|
106
|
+
export class ConnectionError extends ShellXError {
|
|
107
|
+
constructor(message, details) {
|
|
108
|
+
super(message, ErrorCode.CONNECTION_FAILED, details);
|
|
109
|
+
this.name = "ConnectionError";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Operation error class
|
|
114
|
+
*/
|
|
115
|
+
export class OperationError extends ShellXError {
|
|
116
|
+
constructor(message, details) {
|
|
117
|
+
super(message, ErrorCode.OPERATION_FAILED, details);
|
|
118
|
+
this.name = "OperationError";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Element error class
|
|
123
|
+
*/
|
|
124
|
+
export class ElementError extends ShellXError {
|
|
125
|
+
constructor(message, details) {
|
|
126
|
+
super(message, ErrorCode.ELEMENT_NOT_FOUND, details);
|
|
127
|
+
this.name = "ElementError";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validation error class
|
|
132
|
+
*/
|
|
133
|
+
export class ValidationError extends ShellXError {
|
|
134
|
+
constructor(message, details) {
|
|
135
|
+
super(message, ErrorCode.INVALID_INPUT, details);
|
|
136
|
+
this.name = "ValidationError";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4BH;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAe,EACf,IAAa,EACb,OAAiC;IAEjC,MAAM,QAAQ,GAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACnD,IAAI,IAAI;QAAE,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;IAC/B,IAAI,OAAO;QAAE,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;IACxC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAgB,EAChB,QAAgB,EAChB,KAAc;IAEd,MAAM,MAAM,GAAwB,EA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