@bombillazo/error-x 0.4.1 → 0.4.2

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/index.d.cts CHANGED
@@ -164,6 +164,11 @@ interface ErrorXConfig {
164
164
  * - string[]: Custom patterns to match and remove from stack traces
165
165
  */
166
166
  cleanStack?: boolean | string[];
167
+ /**
168
+ * Delimiter to trim stack traces after a specified line
169
+ * When set, stack traces will be trimmed to start after the first line containing this string
170
+ */
171
+ cleanStackDelimiter?: string;
167
172
  }
168
173
  /**
169
174
  * Enhanced Error class with rich metadata, type-safe error handling, and intelligent error conversion.
@@ -177,7 +182,8 @@ interface ErrorXConfig {
177
182
  * docsMap: {
178
183
  * 'AUTH_FAILED': 'errors/authentication',
179
184
  * 'DB_ERROR': 'errors/database'
180
- * }
185
+ * },
186
+ * cleanStackDelimiter: 'my-app-entry' // Clean stack traces after this line
181
187
  * })
182
188
  *
183
189
  * // Basic usage
@@ -286,7 +292,8 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
286
292
  * docsMap: {
287
293
  * 'AUTH_FAILED': 'authentication-errors',
288
294
  * 'DB_ERROR': 'database-errors'
289
- * }
295
+ * },
296
+ * cleanStackDelimiter: 'app-entry-point' // Trim stack traces after this line
290
297
  * })
291
298
  * ```
292
299
  */
@@ -296,6 +303,17 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
296
303
  * Returns null if no configuration has been set.
297
304
  */
298
305
  static getConfig(): ErrorXConfig | null;
306
+ /**
307
+ * Reset global configuration to null.
308
+ * Useful for testing or when you want to clear all configuration.
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * ErrorX.resetConfig()
313
+ * const config = ErrorX.getConfig() // null
314
+ * ```
315
+ */
316
+ static resetConfig(): void;
299
317
  /**
300
318
  * Validates HTTP status code to ensure it's within valid range (100-599)
301
319
  *
@@ -343,28 +361,24 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
343
361
  */
344
362
  private static preserveOriginalStackFromCause;
345
363
  /**
346
- * Cleans the stack trace by removing ErrorX internal method calls.
364
+ * Cleans a stack trace by removing ErrorX internal method calls and optionally trimming after a delimiter.
347
365
  * This provides cleaner stack traces that focus on user code.
348
366
  *
349
- * @param stack - Raw stack trace to clean
350
- * @returns Cleaned stack trace without ErrorX internal calls
351
- */
352
- private static cleanStack;
353
- /**
354
- * Processes an error's stack trace to trim it after a specified delimiter.
355
- * Useful for removing irrelevant stack frames before a specific function.
356
- *
357
- * @param error - Error whose stack to process
358
- * @param delimiter - String to search for in stack lines
359
- * @returns Processed stack trace starting after the delimiter
367
+ * @param stack - Raw stack trace string to clean
368
+ * @param delimiter - Optional delimiter to trim stack trace after (overrides config delimiter)
369
+ * @returns Cleaned stack trace without internal calls and optionally trimmed after delimiter
360
370
  *
361
371
  * @example
362
372
  * ```typescript
363
- * const processed = ErrorX.processErrorStack(error, 'my-app-entry')
373
+ * // Clean with pattern-based removal only
374
+ * const cleaned = ErrorX.cleanStack(error.stack)
375
+ *
376
+ * // Clean and trim after delimiter
377
+ * const trimmed = ErrorX.cleanStack(error.stack, 'my-app-entry')
364
378
  * // Returns stack trace starting after the line containing 'my-app-entry'
365
379
  * ```
366
380
  */
367
- private static processErrorStack;
381
+ static cleanStack(stack?: string, delimiter?: string): string;
368
382
  /**
369
383
  * Creates a new ErrorX instance with additional metadata merged with existing metadata.
370
384
  * The original error properties are preserved while extending the metadata.
@@ -444,21 +458,6 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
444
458
  static from(error: Error): ErrorX;
445
459
  static from(error: string): ErrorX;
446
460
  static from(error: unknown): ErrorX;
447
- /**
448
- * Creates a new ErrorX instance with cleaned stack trace using the specified delimiter.
449
- * Returns the same instance if no delimiter is provided or no stack is available.
450
- *
451
- * @param delimiter - Optional string to search for in stack lines
452
- * @returns New ErrorX instance with cleaned stack trace, or the same instance if no cleaning needed
453
- *
454
- * @example
455
- * ```typescript
456
- * const error = new ErrorX({ message: 'Database error' })
457
- * const cleanedError = error.cleanStackTrace('database-layer')
458
- * // Returns new ErrorX with stack trace starting after 'database-layer'
459
- * ```
460
- */
461
- cleanStackTrace(delimiter?: string): ErrorX<TMetadata>;
462
461
  /**
463
462
  * Converts the ErrorX instance to a detailed string representation.
464
463
  * Includes error name, message, code, timestamp, metadata, and stack trace.
package/dist/index.d.ts CHANGED
@@ -164,6 +164,11 @@ interface ErrorXConfig {
164
164
  * - string[]: Custom patterns to match and remove from stack traces
165
165
  */
166
166
  cleanStack?: boolean | string[];
167
+ /**
168
+ * Delimiter to trim stack traces after a specified line
169
+ * When set, stack traces will be trimmed to start after the first line containing this string
170
+ */
171
+ cleanStackDelimiter?: string;
167
172
  }
168
173
  /**
169
174
  * Enhanced Error class with rich metadata, type-safe error handling, and intelligent error conversion.
@@ -177,7 +182,8 @@ interface ErrorXConfig {
177
182
  * docsMap: {
178
183
  * 'AUTH_FAILED': 'errors/authentication',
179
184
  * 'DB_ERROR': 'errors/database'
180
- * }
185
+ * },
186
+ * cleanStackDelimiter: 'my-app-entry' // Clean stack traces after this line
181
187
  * })
182
188
  *
183
189
  * // Basic usage
@@ -286,7 +292,8 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
286
292
  * docsMap: {
287
293
  * 'AUTH_FAILED': 'authentication-errors',
288
294
  * 'DB_ERROR': 'database-errors'
289
- * }
295
+ * },
296
+ * cleanStackDelimiter: 'app-entry-point' // Trim stack traces after this line
290
297
  * })
291
298
  * ```
292
299
  */
@@ -296,6 +303,17 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
296
303
  * Returns null if no configuration has been set.
297
304
  */
298
305
  static getConfig(): ErrorXConfig | null;
306
+ /**
307
+ * Reset global configuration to null.
308
+ * Useful for testing or when you want to clear all configuration.
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * ErrorX.resetConfig()
313
+ * const config = ErrorX.getConfig() // null
314
+ * ```
315
+ */
316
+ static resetConfig(): void;
299
317
  /**
300
318
  * Validates HTTP status code to ensure it's within valid range (100-599)
301
319
  *
@@ -343,28 +361,24 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
343
361
  */
344
362
  private static preserveOriginalStackFromCause;
345
363
  /**
346
- * Cleans the stack trace by removing ErrorX internal method calls.
364
+ * Cleans a stack trace by removing ErrorX internal method calls and optionally trimming after a delimiter.
347
365
  * This provides cleaner stack traces that focus on user code.
348
366
  *
349
- * @param stack - Raw stack trace to clean
350
- * @returns Cleaned stack trace without ErrorX internal calls
351
- */
352
- private static cleanStack;
353
- /**
354
- * Processes an error's stack trace to trim it after a specified delimiter.
355
- * Useful for removing irrelevant stack frames before a specific function.
356
- *
357
- * @param error - Error whose stack to process
358
- * @param delimiter - String to search for in stack lines
359
- * @returns Processed stack trace starting after the delimiter
367
+ * @param stack - Raw stack trace string to clean
368
+ * @param delimiter - Optional delimiter to trim stack trace after (overrides config delimiter)
369
+ * @returns Cleaned stack trace without internal calls and optionally trimmed after delimiter
360
370
  *
361
371
  * @example
362
372
  * ```typescript
363
- * const processed = ErrorX.processErrorStack(error, 'my-app-entry')
373
+ * // Clean with pattern-based removal only
374
+ * const cleaned = ErrorX.cleanStack(error.stack)
375
+ *
376
+ * // Clean and trim after delimiter
377
+ * const trimmed = ErrorX.cleanStack(error.stack, 'my-app-entry')
364
378
  * // Returns stack trace starting after the line containing 'my-app-entry'
365
379
  * ```
366
380
  */
367
- private static processErrorStack;
381
+ static cleanStack(stack?: string, delimiter?: string): string;
368
382
  /**
369
383
  * Creates a new ErrorX instance with additional metadata merged with existing metadata.
370
384
  * The original error properties are preserved while extending the metadata.
@@ -444,21 +458,6 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
444
458
  static from(error: Error): ErrorX;
445
459
  static from(error: string): ErrorX;
446
460
  static from(error: unknown): ErrorX;
447
- /**
448
- * Creates a new ErrorX instance with cleaned stack trace using the specified delimiter.
449
- * Returns the same instance if no delimiter is provided or no stack is available.
450
- *
451
- * @param delimiter - Optional string to search for in stack lines
452
- * @returns New ErrorX instance with cleaned stack trace, or the same instance if no cleaning needed
453
- *
454
- * @example
455
- * ```typescript
456
- * const error = new ErrorX({ message: 'Database error' })
457
- * const cleanedError = error.cleanStackTrace('database-layer')
458
- * // Returns new ErrorX with stack trace starting after 'database-layer'
459
- * ```
460
- */
461
- cleanStackTrace(delimiter?: string): ErrorX<TMetadata>;
462
461
  /**
463
462
  * Converts the ErrorX instance to a detailed string representation.
464
463
  * Includes error name, message, code, timestamp, metadata, and stack trace.
package/dist/index.js CHANGED
@@ -175,7 +175,8 @@ var ErrorX = class _ErrorX extends Error {
175
175
  * docsMap: {
176
176
  * 'AUTH_FAILED': 'authentication-errors',
177
177
  * 'DB_ERROR': 'database-errors'
178
- * }
178
+ * },
179
+ * cleanStackDelimiter: 'app-entry-point' // Trim stack traces after this line
179
180
  * })
180
181
  * ```
181
182
  */
@@ -189,6 +190,19 @@ var ErrorX = class _ErrorX extends Error {
189
190
  static getConfig() {
190
191
  return _ErrorX._config;
191
192
  }
193
+ /**
194
+ * Reset global configuration to null.
195
+ * Useful for testing or when you want to clear all configuration.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * ErrorX.resetConfig()
200
+ * const config = ErrorX.getConfig() // null
201
+ * ```
202
+ */
203
+ static resetConfig() {
204
+ _ErrorX._config = null;
205
+ }
192
206
  /**
193
207
  * Validates HTTP status code to ensure it's within valid range (100-599)
194
208
  *
@@ -276,13 +290,24 @@ var ErrorX = class _ErrorX extends Error {
276
290
  return [newErrorFirstLine, ...originalStackTrace].join("\n");
277
291
  }
278
292
  /**
279
- * Cleans the stack trace by removing ErrorX internal method calls.
293
+ * Cleans a stack trace by removing ErrorX internal method calls and optionally trimming after a delimiter.
280
294
  * This provides cleaner stack traces that focus on user code.
281
295
  *
282
- * @param stack - Raw stack trace to clean
283
- * @returns Cleaned stack trace without ErrorX internal calls
296
+ * @param stack - Raw stack trace string to clean
297
+ * @param delimiter - Optional delimiter to trim stack trace after (overrides config delimiter)
298
+ * @returns Cleaned stack trace without internal calls and optionally trimmed after delimiter
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * // Clean with pattern-based removal only
303
+ * const cleaned = ErrorX.cleanStack(error.stack)
304
+ *
305
+ * // Clean and trim after delimiter
306
+ * const trimmed = ErrorX.cleanStack(error.stack, 'my-app-entry')
307
+ * // Returns stack trace starting after the line containing 'my-app-entry'
308
+ * ```
284
309
  */
285
- static cleanStack(stack) {
310
+ static cleanStack(stack, delimiter) {
286
311
  if (!stack) return "";
287
312
  const config = _ErrorX.getConfig();
288
313
  const cleanStackConfig = config?.cleanStack ?? true;
@@ -306,30 +331,15 @@ var ErrorX = class _ErrorX extends Error {
306
331
  }
307
332
  cleanedLines.push(line);
308
333
  }
309
- return cleanedLines.join("\n");
310
- }
311
- /**
312
- * Processes an error's stack trace to trim it after a specified delimiter.
313
- * Useful for removing irrelevant stack frames before a specific function.
314
- *
315
- * @param error - Error whose stack to process
316
- * @param delimiter - String to search for in stack lines
317
- * @returns Processed stack trace starting after the delimiter
318
- *
319
- * @example
320
- * ```typescript
321
- * const processed = ErrorX.processErrorStack(error, 'my-app-entry')
322
- * // Returns stack trace starting after the line containing 'my-app-entry'
323
- * ```
324
- */
325
- static processErrorStack(error, delimiter) {
326
- let stack = error.stack ?? "";
327
- const stackLines = stack.split("\n");
328
- const delimiterIndex = stackLines.findIndex((line) => line.includes(delimiter));
329
- if (delimiterIndex !== -1) {
330
- stack = stackLines.slice(delimiterIndex + 1).join("\n");
334
+ let cleanedStack = cleanedLines.join("\n");
335
+ const activeDelimiter = delimiter ?? config?.cleanStackDelimiter;
336
+ if (activeDelimiter) {
337
+ const delimiterIndex = cleanedLines.findIndex((line) => line.includes(activeDelimiter));
338
+ if (delimiterIndex !== -1) {
339
+ cleanedStack = cleanedLines.slice(delimiterIndex + 1).join("\n");
340
+ }
331
341
  }
332
- return stack;
342
+ return cleanedStack;
333
343
  }
334
344
  /**
335
345
  * Creates a new ErrorX instance with additional metadata merged with existing metadata.
@@ -494,43 +504,6 @@ var ErrorX = class _ErrorX extends Error {
494
504
  const options = _ErrorX.convertUnknownToOptions(error);
495
505
  return new _ErrorX(options);
496
506
  }
497
- /**
498
- * Creates a new ErrorX instance with cleaned stack trace using the specified delimiter.
499
- * Returns the same instance if no delimiter is provided or no stack is available.
500
- *
501
- * @param delimiter - Optional string to search for in stack lines
502
- * @returns New ErrorX instance with cleaned stack trace, or the same instance if no cleaning needed
503
- *
504
- * @example
505
- * ```typescript
506
- * const error = new ErrorX({ message: 'Database error' })
507
- * const cleanedError = error.cleanStackTrace('database-layer')
508
- * // Returns new ErrorX with stack trace starting after 'database-layer'
509
- * ```
510
- */
511
- cleanStackTrace(delimiter) {
512
- if (delimiter && this.stack) {
513
- const options = {
514
- message: this.message,
515
- name: this.name,
516
- code: this.code,
517
- uiMessage: this.uiMessage,
518
- cause: this.cause,
519
- httpStatus: this.httpStatus,
520
- type: this.type,
521
- sourceUrl: this.sourceUrl,
522
- docsUrl: this.docsUrl,
523
- source: this.source
524
- };
525
- if (this.metadata !== void 0) {
526
- options.metadata = this.metadata;
527
- }
528
- const newError = new _ErrorX(options);
529
- newError.stack = _ErrorX.processErrorStack(this, delimiter);
530
- return newError;
531
- }
532
- return this;
533
- }
534
507
  /**
535
508
  * Converts the ErrorX instance to a detailed string representation.
536
509
  * Includes error name, message, code, timestamp, metadata, and stack trace.