forked from getsentry/XcodeBuildMCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.ts
More file actions
136 lines (126 loc) · 3.58 KB
/
errors.ts
File metadata and controls
136 lines (126 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { ToolResponse } from '../types/common.ts';
/**
* Error Utilities - Type-safe error hierarchy for the application
*
* This utility module defines a structured error hierarchy for the application,
* providing specialized error types for different failure scenarios. Using these
* typed errors enables more precise error handling, improves debugging, and
* provides better error messages to users.
*
* Responsibilities:
* - Providing a base error class (XcodeBuildMCPError) for all application errors
* - Defining specialized error subtypes for different error categories:
* - ValidationError: Parameter validation failures
* - SystemError: Underlying system/OS issues
* - ConfigurationError: Application configuration problems
* - SimulatorError: iOS simulator-specific failures
* - AxeError: axe-specific errors
*
* The structured hierarchy allows error consumers to handle errors with the
* appropriate level of specificity using instanceof checks or catch clauses.
*/
/**
* Custom error types for XcodeBuildMCP
*/
/**
* Base error class for XcodeBuildMCP errors
*/
export class XcodeBuildMCPError extends Error {
constructor(message: string) {
super(message);
this.name = 'XcodeBuildMCPError';
// This is necessary for proper inheritance in TypeScript
Object.setPrototypeOf(this, XcodeBuildMCPError.prototype);
}
}
/**
* Error thrown when validation of parameters fails
*/
export class ValidationError extends XcodeBuildMCPError {
constructor(
message: string,
public paramName?: string,
) {
super(message);
this.name = 'ValidationError';
Object.setPrototypeOf(this, ValidationError.prototype);
}
}
/**
* Error thrown for system-level errors (file access, permissions, etc.)
*/
export class SystemError extends XcodeBuildMCPError {
constructor(
message: string,
public originalError?: Error,
) {
super(message);
this.name = 'SystemError';
Object.setPrototypeOf(this, SystemError.prototype);
}
}
/**
* Error thrown for configuration issues
*/
export class ConfigurationError extends XcodeBuildMCPError {
constructor(message: string) {
super(message);
this.name = 'ConfigurationError';
Object.setPrototypeOf(this, ConfigurationError.prototype);
}
}
/**
* Error thrown for simulator-specific errors
*/
export class SimulatorError extends XcodeBuildMCPError {
constructor(
message: string,
public simulatorName?: string,
public simulatorId?: string,
) {
super(message);
this.name = 'SimulatorError';
Object.setPrototypeOf(this, SimulatorError.prototype);
}
}
/**
* Error thrown for axe-specific errors
*/
export class AxeError extends XcodeBuildMCPError {
constructor(
message: string,
public command?: string, // The axe command that failed
public axeOutput?: string, // Output from axe
public simulatorId?: string,
) {
super(message);
this.name = 'AxeError';
Object.setPrototypeOf(this, AxeError.prototype);
}
}
// Helper to create a standard error response
export function createErrorResponse(message: string, details?: string): ToolResponse {
const detailText = details ? `\nDetails: ${details}` : '';
return {
content: [
{
type: 'text',
text: `Error: ${message}${detailText}`,
},
],
isError: true,
};
}
/**
* Error class for missing dependencies
*/
export class DependencyError extends ConfigurationError {
constructor(
message: string,
public details?: string,
) {
super(message);
this.name = 'DependencyError';
Object.setPrototypeOf(this, DependencyError.prototype);
}
}