@veloxts/core 0.3.4 → 0.3.6
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/dist/app.d.ts.map +1 -1
- package/dist/app.js.map +1 -1
- package/dist/context.d.ts +26 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +29 -0
- package/dist/context.js.map +1 -1
- package/dist/di/container.d.ts.map +1 -1
- package/dist/di/container.js +14 -8
- package/dist/di/container.js.map +1 -1
- package/dist/di/decorators.d.ts +22 -8
- package/dist/di/decorators.d.ts.map +1 -1
- package/dist/di/decorators.js.map +1 -1
- package/dist/di/index.d.ts +2 -2
- package/dist/di/index.d.ts.map +1 -1
- package/dist/di/index.js +7 -7
- package/dist/di/index.js.map +1 -1
- package/dist/di/providers.d.ts +48 -8
- package/dist/di/providers.d.ts.map +1 -1
- package/dist/di/providers.js.map +1 -1
- package/dist/di/scope.d.ts +21 -0
- package/dist/di/scope.d.ts.map +1 -1
- package/dist/di/scope.js +32 -0
- package/dist/di/scope.js.map +1 -1
- package/dist/errors/catalog.d.ts +79 -0
- package/dist/errors/catalog.d.ts.map +1 -0
- package/dist/errors/catalog.js +492 -0
- package/dist/errors/catalog.js.map +1 -0
- package/dist/errors/formatter.d.ts +101 -0
- package/dist/errors/formatter.d.ts.map +1 -0
- package/dist/errors/formatter.js +330 -0
- package/dist/errors/formatter.js.map +1 -0
- package/dist/errors/index.d.ts +14 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +16 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors.d.ts +35 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +57 -4
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/package.json +12 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Formatter - Pretty terminal output with fix suggestions
|
|
3
|
+
*
|
|
4
|
+
* Inspired by Laravel's Ignition error pages, this module provides
|
|
5
|
+
* beautiful, informative error messages with actionable suggestions.
|
|
6
|
+
*
|
|
7
|
+
* @module errors/formatter
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Extracted error location from stack trace
|
|
11
|
+
*/
|
|
12
|
+
export interface ErrorLocation {
|
|
13
|
+
file: string;
|
|
14
|
+
line: number;
|
|
15
|
+
column?: number;
|
|
16
|
+
functionName?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse stack trace to extract error location
|
|
20
|
+
*
|
|
21
|
+
* @param error - The error to parse
|
|
22
|
+
* @returns Location info or undefined
|
|
23
|
+
*/
|
|
24
|
+
export declare function extractErrorLocation(error: Error): ErrorLocation | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Options for error formatting
|
|
27
|
+
*/
|
|
28
|
+
export interface FormatErrorOptions {
|
|
29
|
+
/** Include the stack trace (default: false in production) */
|
|
30
|
+
includeStack?: boolean;
|
|
31
|
+
/** Include the fix suggestion (default: true) */
|
|
32
|
+
includeFix?: boolean;
|
|
33
|
+
/** Include documentation link (default: true) */
|
|
34
|
+
includeDocs?: boolean;
|
|
35
|
+
/** Include related error codes (default: true) */
|
|
36
|
+
includeSeeAlso?: boolean;
|
|
37
|
+
/** Maximum width for text wrapping */
|
|
38
|
+
maxWidth?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Format an error for terminal output with fix suggestions
|
|
42
|
+
*
|
|
43
|
+
* @param error - The error to format
|
|
44
|
+
* @param catalogCode - Optional catalog error code
|
|
45
|
+
* @param options - Formatting options
|
|
46
|
+
* @returns Formatted error string for terminal display
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* try {
|
|
51
|
+
* // ... code that throws
|
|
52
|
+
* } catch (error) {
|
|
53
|
+
* console.error(formatError(error, 'VELOX-1001'));
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function formatError(error: Error, catalogCode?: string, options?: FormatErrorOptions): string;
|
|
58
|
+
/**
|
|
59
|
+
* Format an error for JSON API response
|
|
60
|
+
* Includes catalog metadata but not stack traces
|
|
61
|
+
*
|
|
62
|
+
* @param error - The error to format
|
|
63
|
+
* @param catalogCode - Optional catalog error code
|
|
64
|
+
* @returns JSON-serializable error object
|
|
65
|
+
*/
|
|
66
|
+
export declare function formatErrorForApi(error: Error & {
|
|
67
|
+
statusCode?: number;
|
|
68
|
+
code?: string;
|
|
69
|
+
fields?: Record<string, string>;
|
|
70
|
+
}, catalogCode?: string): Record<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Format a short one-line error summary
|
|
73
|
+
*
|
|
74
|
+
* @param error - The error
|
|
75
|
+
* @param catalogCode - Optional catalog code
|
|
76
|
+
* @returns One-line error string
|
|
77
|
+
*/
|
|
78
|
+
export declare function formatErrorOneLine(error: Error, catalogCode?: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Log an error with pretty formatting
|
|
81
|
+
*
|
|
82
|
+
* @param error - The error to log
|
|
83
|
+
* @param catalogCode - Optional catalog error code
|
|
84
|
+
*/
|
|
85
|
+
export declare function logError(error: Error, catalogCode?: string): void;
|
|
86
|
+
/**
|
|
87
|
+
* Log a warning with pretty formatting
|
|
88
|
+
*
|
|
89
|
+
* @param message - Warning message
|
|
90
|
+
* @param suggestion - Optional fix suggestion
|
|
91
|
+
*/
|
|
92
|
+
export declare function logWarning(message: string, suggestion?: string): void;
|
|
93
|
+
/**
|
|
94
|
+
* Log a deprecation warning
|
|
95
|
+
*
|
|
96
|
+
* @param oldApi - The deprecated API
|
|
97
|
+
* @param newApi - The replacement API
|
|
98
|
+
* @param removeVersion - Version when it will be removed
|
|
99
|
+
*/
|
|
100
|
+
export declare function logDeprecation(oldApi: string, newApi: string, removeVersion?: string): void;
|
|
101
|
+
//# sourceMappingURL=formatter.d.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AAE,MAAM,GAAG,MAAM,CAQ7E;AAMD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CASrE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAM3F"}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Formatter - Pretty terminal output with fix suggestions
|
|
3
|
+
*
|
|
4
|
+
* Inspired by Laravel's Ignition error pages, this module provides
|
|
5
|
+
* beautiful, informative error messages with actionable suggestions.
|
|
6
|
+
*
|
|
7
|
+
* @module errors/formatter
|
|
8
|
+
*/
|
|
9
|
+
import { getErrorEntry } from './catalog.js';
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// ANSI Color Codes (for terminal output)
|
|
12
|
+
// ============================================================================
|
|
13
|
+
const COLORS = {
|
|
14
|
+
reset: '\x1b[0m',
|
|
15
|
+
bold: '\x1b[1m',
|
|
16
|
+
dim: '\x1b[2m',
|
|
17
|
+
// Text colors
|
|
18
|
+
red: '\x1b[31m',
|
|
19
|
+
green: '\x1b[32m',
|
|
20
|
+
yellow: '\x1b[33m',
|
|
21
|
+
blue: '\x1b[34m',
|
|
22
|
+
magenta: '\x1b[35m',
|
|
23
|
+
cyan: '\x1b[36m',
|
|
24
|
+
white: '\x1b[37m',
|
|
25
|
+
gray: '\x1b[90m',
|
|
26
|
+
// Background colors
|
|
27
|
+
bgRed: '\x1b[41m',
|
|
28
|
+
bgYellow: '\x1b[43m',
|
|
29
|
+
bgBlue: '\x1b[44m',
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Check if colors should be enabled
|
|
33
|
+
* Respects NO_COLOR env var and TTY detection
|
|
34
|
+
*/
|
|
35
|
+
function shouldUseColors() {
|
|
36
|
+
if (process.env.NO_COLOR)
|
|
37
|
+
return false;
|
|
38
|
+
if (process.env.FORCE_COLOR)
|
|
39
|
+
return true;
|
|
40
|
+
return process.stdout.isTTY ?? false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Apply color to text if colors are enabled
|
|
44
|
+
*/
|
|
45
|
+
function color(text, ...codes) {
|
|
46
|
+
if (!shouldUseColors())
|
|
47
|
+
return text;
|
|
48
|
+
const prefix = codes.map((c) => COLORS[c]).join('');
|
|
49
|
+
return `${prefix}${text}${COLORS.reset}`;
|
|
50
|
+
}
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// Formatting Helpers
|
|
53
|
+
// ============================================================================
|
|
54
|
+
/**
|
|
55
|
+
* Create a horizontal divider line
|
|
56
|
+
*/
|
|
57
|
+
function divider(char = '─', length = 70) {
|
|
58
|
+
return char.repeat(length);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Indent text by a number of spaces
|
|
62
|
+
*/
|
|
63
|
+
function indent(text, spaces = 2) {
|
|
64
|
+
const pad = ' '.repeat(spaces);
|
|
65
|
+
return text
|
|
66
|
+
.split('\n')
|
|
67
|
+
.map((line) => `${pad}${line}`)
|
|
68
|
+
.join('\n');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Wrap text to a maximum width
|
|
72
|
+
*/
|
|
73
|
+
function wrapText(text, maxWidth = 68) {
|
|
74
|
+
const words = text.split(' ');
|
|
75
|
+
const lines = [];
|
|
76
|
+
let currentLine = '';
|
|
77
|
+
for (const word of words) {
|
|
78
|
+
if (currentLine.length + word.length + 1 <= maxWidth) {
|
|
79
|
+
currentLine += (currentLine ? ' ' : '') + word;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (currentLine)
|
|
83
|
+
lines.push(currentLine);
|
|
84
|
+
currentLine = word;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (currentLine)
|
|
88
|
+
lines.push(currentLine);
|
|
89
|
+
return lines.join('\n');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse stack trace to extract error location
|
|
93
|
+
*
|
|
94
|
+
* @param error - The error to parse
|
|
95
|
+
* @returns Location info or undefined
|
|
96
|
+
*/
|
|
97
|
+
export function extractErrorLocation(error) {
|
|
98
|
+
if (!error.stack)
|
|
99
|
+
return undefined;
|
|
100
|
+
// Skip the first line (error message) and internal frames
|
|
101
|
+
const lines = error.stack.split('\n').slice(1);
|
|
102
|
+
for (const line of lines) {
|
|
103
|
+
// Skip internal node_modules frames
|
|
104
|
+
if (line.includes('node_modules'))
|
|
105
|
+
continue;
|
|
106
|
+
if (line.includes('node:internal'))
|
|
107
|
+
continue;
|
|
108
|
+
// Match V8 stack trace format: "at functionName (file:line:col)"
|
|
109
|
+
// or "at file:line:col"
|
|
110
|
+
const match = line.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/);
|
|
111
|
+
if (match) {
|
|
112
|
+
return {
|
|
113
|
+
functionName: match[1],
|
|
114
|
+
file: match[2],
|
|
115
|
+
line: parseInt(match[3], 10),
|
|
116
|
+
column: parseInt(match[4], 10),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
// ============================================================================
|
|
123
|
+
// Main Formatting Functions
|
|
124
|
+
// ============================================================================
|
|
125
|
+
/**
|
|
126
|
+
* Format an error for terminal output with fix suggestions
|
|
127
|
+
*
|
|
128
|
+
* @param error - The error to format
|
|
129
|
+
* @param catalogCode - Optional catalog error code
|
|
130
|
+
* @param options - Formatting options
|
|
131
|
+
* @returns Formatted error string for terminal display
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* try {
|
|
136
|
+
* // ... code that throws
|
|
137
|
+
* } catch (error) {
|
|
138
|
+
* console.error(formatError(error, 'VELOX-1001'));
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export function formatError(error, catalogCode, options = {}) {
|
|
143
|
+
const { includeStack = process.env.NODE_ENV !== 'production', includeFix = true, includeDocs = true, includeSeeAlso = true, maxWidth = 68, } = options;
|
|
144
|
+
const entry = catalogCode ? getErrorEntry(catalogCode) : undefined;
|
|
145
|
+
const location = extractErrorLocation(error);
|
|
146
|
+
const lines = [];
|
|
147
|
+
// Header
|
|
148
|
+
lines.push('');
|
|
149
|
+
lines.push(color(divider('═'), 'red'));
|
|
150
|
+
lines.push('');
|
|
151
|
+
// Error code and title
|
|
152
|
+
if (entry) {
|
|
153
|
+
lines.push(` ${color(entry.code, 'red', 'bold')} ${color(entry.title, 'white', 'bold')}`);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
lines.push(` ${color(error.name, 'red', 'bold')}`);
|
|
157
|
+
}
|
|
158
|
+
lines.push('');
|
|
159
|
+
// Error message
|
|
160
|
+
lines.push(indent(wrapText(error.message, maxWidth)));
|
|
161
|
+
lines.push('');
|
|
162
|
+
// Location
|
|
163
|
+
if (location) {
|
|
164
|
+
lines.push(color(divider('─'), 'gray'));
|
|
165
|
+
lines.push('');
|
|
166
|
+
lines.push(` ${color('Location:', 'cyan', 'bold')}`);
|
|
167
|
+
lines.push('');
|
|
168
|
+
const loc = `${location.file}:${location.line}${location.column ? `:${location.column}` : ''}`;
|
|
169
|
+
lines.push(` ${color('→', 'yellow')} ${color(loc, 'white')}`);
|
|
170
|
+
if (location.functionName) {
|
|
171
|
+
lines.push(` ${color('in', 'gray')} ${color(location.functionName, 'cyan')}`);
|
|
172
|
+
}
|
|
173
|
+
lines.push('');
|
|
174
|
+
}
|
|
175
|
+
// Description from catalog
|
|
176
|
+
if (entry?.description) {
|
|
177
|
+
lines.push(color(divider('─'), 'gray'));
|
|
178
|
+
lines.push('');
|
|
179
|
+
lines.push(` ${color('Why this happens:', 'cyan', 'bold')}`);
|
|
180
|
+
lines.push('');
|
|
181
|
+
lines.push(indent(wrapText(entry.description, maxWidth)));
|
|
182
|
+
lines.push('');
|
|
183
|
+
}
|
|
184
|
+
// Fix suggestion
|
|
185
|
+
if (includeFix && entry?.fix) {
|
|
186
|
+
lines.push(color(divider('─'), 'gray'));
|
|
187
|
+
lines.push('');
|
|
188
|
+
lines.push(` ${color('How to fix:', 'green', 'bold')}`);
|
|
189
|
+
lines.push('');
|
|
190
|
+
lines.push(indent(wrapText(entry.fix.suggestion, maxWidth)));
|
|
191
|
+
if (entry.fix.example) {
|
|
192
|
+
lines.push('');
|
|
193
|
+
lines.push(` ${color('Example:', 'yellow')}`);
|
|
194
|
+
lines.push('');
|
|
195
|
+
// Format code example with syntax highlighting hint
|
|
196
|
+
const exampleLines = entry.fix.example.split('\n');
|
|
197
|
+
for (const exLine of exampleLines) {
|
|
198
|
+
if (exLine.trim().startsWith('#') || exLine.trim().startsWith('//')) {
|
|
199
|
+
lines.push(` ${color(exLine, 'gray')}`);
|
|
200
|
+
}
|
|
201
|
+
else if (exLine.trim().startsWith('+')) {
|
|
202
|
+
lines.push(` ${color(exLine, 'green')}`);
|
|
203
|
+
}
|
|
204
|
+
else if (exLine.trim().startsWith('-')) {
|
|
205
|
+
lines.push(` ${color(exLine, 'red')}`);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
lines.push(` ${color(exLine, 'white')}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
lines.push('');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Documentation link
|
|
215
|
+
if (includeDocs && entry?.docsUrl) {
|
|
216
|
+
lines.push(color(divider('─'), 'gray'));
|
|
217
|
+
lines.push('');
|
|
218
|
+
lines.push(` ${color('Documentation:', 'blue', 'bold')}`);
|
|
219
|
+
lines.push(` ${color(entry.docsUrl, 'cyan')}`);
|
|
220
|
+
lines.push('');
|
|
221
|
+
}
|
|
222
|
+
// Related errors
|
|
223
|
+
if (includeSeeAlso && entry?.seeAlso && entry.seeAlso.length > 0) {
|
|
224
|
+
lines.push(` ${color('See also:', 'gray')} ${entry.seeAlso.map((c) => color(c, 'yellow')).join(', ')}`);
|
|
225
|
+
lines.push('');
|
|
226
|
+
}
|
|
227
|
+
// Stack trace (development only)
|
|
228
|
+
if (includeStack && error.stack) {
|
|
229
|
+
lines.push(color(divider('─'), 'gray'));
|
|
230
|
+
lines.push('');
|
|
231
|
+
lines.push(` ${color('Stack trace:', 'gray', 'bold')}`);
|
|
232
|
+
lines.push('');
|
|
233
|
+
const stackLines = error.stack.split('\n').slice(1, 8); // First 7 frames
|
|
234
|
+
for (const stackLine of stackLines) {
|
|
235
|
+
lines.push(` ${color(stackLine.trim(), 'gray')}`);
|
|
236
|
+
}
|
|
237
|
+
if (error.stack.split('\n').length > 8) {
|
|
238
|
+
lines.push(` ${color('... more frames hidden', 'dim')}`);
|
|
239
|
+
}
|
|
240
|
+
lines.push('');
|
|
241
|
+
}
|
|
242
|
+
// Footer
|
|
243
|
+
lines.push(color(divider('═'), 'red'));
|
|
244
|
+
lines.push('');
|
|
245
|
+
return lines.join('\n');
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Format an error for JSON API response
|
|
249
|
+
* Includes catalog metadata but not stack traces
|
|
250
|
+
*
|
|
251
|
+
* @param error - The error to format
|
|
252
|
+
* @param catalogCode - Optional catalog error code
|
|
253
|
+
* @returns JSON-serializable error object
|
|
254
|
+
*/
|
|
255
|
+
export function formatErrorForApi(error, catalogCode) {
|
|
256
|
+
const entry = catalogCode ? getErrorEntry(catalogCode) : undefined;
|
|
257
|
+
const response = {
|
|
258
|
+
error: error.name,
|
|
259
|
+
message: error.message,
|
|
260
|
+
statusCode: error.statusCode ?? entry?.statusCode ?? 500,
|
|
261
|
+
code: catalogCode ?? error.code,
|
|
262
|
+
};
|
|
263
|
+
// Include field errors for validation
|
|
264
|
+
if (error.fields) {
|
|
265
|
+
response.fields = error.fields;
|
|
266
|
+
}
|
|
267
|
+
// Include fix suggestion in development
|
|
268
|
+
if (process.env.NODE_ENV !== 'production' && entry?.fix) {
|
|
269
|
+
response.fix = entry.fix.suggestion;
|
|
270
|
+
}
|
|
271
|
+
// Include docs link
|
|
272
|
+
if (entry?.docsUrl) {
|
|
273
|
+
response.docs = entry.docsUrl;
|
|
274
|
+
}
|
|
275
|
+
return response;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Format a short one-line error summary
|
|
279
|
+
*
|
|
280
|
+
* @param error - The error
|
|
281
|
+
* @param catalogCode - Optional catalog code
|
|
282
|
+
* @returns One-line error string
|
|
283
|
+
*/
|
|
284
|
+
export function formatErrorOneLine(error, catalogCode) {
|
|
285
|
+
const entry = catalogCode ? getErrorEntry(catalogCode) : undefined;
|
|
286
|
+
if (entry) {
|
|
287
|
+
return `${color(entry.code, 'red')}: ${error.message}`;
|
|
288
|
+
}
|
|
289
|
+
return `${color(error.name, 'red')}: ${error.message}`;
|
|
290
|
+
}
|
|
291
|
+
// ============================================================================
|
|
292
|
+
// Error Logging Helpers
|
|
293
|
+
// ============================================================================
|
|
294
|
+
/**
|
|
295
|
+
* Log an error with pretty formatting
|
|
296
|
+
*
|
|
297
|
+
* @param error - The error to log
|
|
298
|
+
* @param catalogCode - Optional catalog error code
|
|
299
|
+
*/
|
|
300
|
+
export function logError(error, catalogCode) {
|
|
301
|
+
console.error(formatError(error, catalogCode));
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Log a warning with pretty formatting
|
|
305
|
+
*
|
|
306
|
+
* @param message - Warning message
|
|
307
|
+
* @param suggestion - Optional fix suggestion
|
|
308
|
+
*/
|
|
309
|
+
export function logWarning(message, suggestion) {
|
|
310
|
+
const lines = [];
|
|
311
|
+
lines.push('');
|
|
312
|
+
lines.push(`${color('⚠', 'yellow')} ${color('Warning:', 'yellow', 'bold')} ${message}`);
|
|
313
|
+
if (suggestion) {
|
|
314
|
+
lines.push(` ${color('→', 'gray')} ${suggestion}`);
|
|
315
|
+
}
|
|
316
|
+
lines.push('');
|
|
317
|
+
console.warn(lines.join('\n'));
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Log a deprecation warning
|
|
321
|
+
*
|
|
322
|
+
* @param oldApi - The deprecated API
|
|
323
|
+
* @param newApi - The replacement API
|
|
324
|
+
* @param removeVersion - Version when it will be removed
|
|
325
|
+
*/
|
|
326
|
+
export function logDeprecation(oldApi, newApi, removeVersion) {
|
|
327
|
+
const removal = removeVersion ? ` (will be removed in ${removeVersion})` : '';
|
|
328
|
+
logWarning(`${color(oldApi, 'white')} is deprecated${removal}`, `Use ${color(newApi, 'green')} instead`);
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/errors/formatter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,+EAA+E;AAC/E,yCAAyC;AACzC,+EAA+E;AAE/E,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,GAAG,EAAE,SAAS;IAEd,cAAc;IACd,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,UAAU;IAEhB,oBAAoB;IACpB,KAAK,EAAE,UAAU;IACjB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,UAAU;CACV,CAAC;AAEX;;;GAGG;AACH,SAAS,eAAe;IACtB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,OAAO,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C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,MAAc,EAAE,aAAsB;IACnF,MAAM,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,wBAAwB,aAAa,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9E,UAAU,CACR,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,iBAAiB,OAAO,EAAE,EACnD,OAAO,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VeloxTS Error System
|
|
3
|
+
*
|
|
4
|
+
* Provides enhanced error handling with:
|
|
5
|
+
* - Numbered error codes (VELOX-XXXX)
|
|
6
|
+
* - Fix suggestions with code examples
|
|
7
|
+
* - Pretty terminal formatting
|
|
8
|
+
* - Documentation links
|
|
9
|
+
*
|
|
10
|
+
* @module errors
|
|
11
|
+
*/
|
|
12
|
+
export { ERROR_CATALOG, ERROR_DOMAINS, type ErrorCatalogEntry, type ErrorDomain, getDocsUrl, getErrorEntry, getErrorsByDomain, isKnownErrorCode, } from './catalog.js';
|
|
13
|
+
export { type ErrorLocation, extractErrorLocation, type FormatErrorOptions, formatError, formatErrorForApi, formatErrorOneLine, logDeprecation, logError, logWarning, } from './formatter.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACL,aAAa,EACb,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,KAAK,aAAa,EAClB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,UAAU,GACX,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VeloxTS Error System
|
|
3
|
+
*
|
|
4
|
+
* Provides enhanced error handling with:
|
|
5
|
+
* - Numbered error codes (VELOX-XXXX)
|
|
6
|
+
* - Fix suggestions with code examples
|
|
7
|
+
* - Pretty terminal formatting
|
|
8
|
+
* - Documentation links
|
|
9
|
+
*
|
|
10
|
+
* @module errors
|
|
11
|
+
*/
|
|
12
|
+
// Re-export catalog
|
|
13
|
+
export { ERROR_CATALOG, ERROR_DOMAINS, getDocsUrl, getErrorEntry, getErrorsByDomain, isKnownErrorCode, } from './catalog.js';
|
|
14
|
+
// Re-export formatter
|
|
15
|
+
export { extractErrorLocation, formatError, formatErrorForApi, formatErrorOneLine, logDeprecation, logError, logWarning, } from './formatter.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,oBAAoB;AACpB,OAAO,EACL,aAAa,EACb,aAAa,EAGb,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,sBAAsB;AACtB,OAAO,EAEL,oBAAoB,EAEpB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,UAAU,GACX,MAAM,gBAAgB,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Provides base error classes with HTTP status codes and discriminated unions
|
|
4
4
|
* @module errors
|
|
5
5
|
*/
|
|
6
|
+
export { ERROR_CATALOG, ERROR_DOMAINS, type ErrorCatalogEntry, type ErrorDomain, type ErrorLocation, extractErrorLocation, type FormatErrorOptions, formatError, formatErrorForApi, formatErrorOneLine, getDocsUrl, getErrorEntry, getErrorsByDomain, isKnownErrorCode, logDeprecation, logError, logWarning, } from './errors/index.js';
|
|
6
7
|
/**
|
|
7
8
|
* Known error codes in the VeloxTS framework core
|
|
8
9
|
* Can be extended via declaration merging by plugins
|
|
@@ -104,11 +105,19 @@ export declare function isNotFoundErrorResponse(response: ErrorResponse): respon
|
|
|
104
105
|
*
|
|
105
106
|
* @example
|
|
106
107
|
* ```typescript
|
|
108
|
+
* // Basic usage
|
|
107
109
|
* throw new VeloxError('Something went wrong', 500);
|
|
108
110
|
* ```
|
|
109
111
|
*
|
|
110
112
|
* @example
|
|
111
113
|
* ```typescript
|
|
114
|
+
* // With catalog code for rich error details
|
|
115
|
+
* throw new VeloxError('Database connection failed', 503, 'VELOX-4001');
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* // With legacy string code
|
|
112
121
|
* throw new VeloxError('Database connection failed', 503, 'DB_CONNECTION_ERROR');
|
|
113
122
|
* ```
|
|
114
123
|
*/
|
|
@@ -118,23 +127,45 @@ export declare class VeloxError<TCode extends string = string> extends Error {
|
|
|
118
127
|
*/
|
|
119
128
|
readonly statusCode: number;
|
|
120
129
|
/**
|
|
121
|
-
*
|
|
130
|
+
* Error code for programmatic error handling
|
|
131
|
+
* Can be a catalog code (VELOX-XXXX) or legacy string code
|
|
122
132
|
*/
|
|
123
133
|
readonly code?: TCode;
|
|
134
|
+
/**
|
|
135
|
+
* Fix suggestion for developers (populated from catalog)
|
|
136
|
+
*/
|
|
137
|
+
readonly fix?: string;
|
|
138
|
+
/**
|
|
139
|
+
* Documentation URL for this error
|
|
140
|
+
*/
|
|
141
|
+
readonly docsUrl?: string;
|
|
124
142
|
/**
|
|
125
143
|
* Creates a new VeloxError instance
|
|
126
144
|
*
|
|
127
145
|
* @param message - Human-readable error message
|
|
128
146
|
* @param statusCode - HTTP status code (default: 500)
|
|
129
|
-
* @param code - Optional error code
|
|
147
|
+
* @param code - Optional error code (VELOX-XXXX catalog code or legacy string)
|
|
130
148
|
*/
|
|
131
149
|
constructor(message: string, statusCode?: number, code?: TCode);
|
|
132
150
|
/**
|
|
133
151
|
* Converts error to JSON format for API responses
|
|
134
152
|
*
|
|
135
|
-
* @returns Error response object
|
|
153
|
+
* @returns Error response object with optional fix suggestion in development
|
|
154
|
+
*/
|
|
155
|
+
toJSON(): GenericErrorResponse & {
|
|
156
|
+
fix?: string;
|
|
157
|
+
docs?: string;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Format error for terminal display with colors and fix suggestions
|
|
161
|
+
*
|
|
162
|
+
* @returns Formatted error string
|
|
163
|
+
*/
|
|
164
|
+
format(): string;
|
|
165
|
+
/**
|
|
166
|
+
* Log this error with pretty formatting
|
|
136
167
|
*/
|
|
137
|
-
|
|
168
|
+
log(): void;
|
|
138
169
|
}
|
|
139
170
|
/**
|
|
140
171
|
* Validation error for invalid user input
|
|
@@ -294,5 +325,4 @@ export declare function isConfigurationError(error: unknown): error is Configura
|
|
|
294
325
|
* ```
|
|
295
326
|
*/
|
|
296
327
|
export declare function assertNever(value: never): never;
|
|
297
|
-
export {};
|
|
298
328
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EACL,aAAa,EACb,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,WA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