File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 ValidateKeys ,
88 BreadcrumbExtractor as BreadcrumbExtractorType ,
99 BreadcrumbExtractorUtil ,
10+ normalizeThrown ,
1011} from '../utils' ;
1112import { Reporter , NoopReporter } from './reporter' ;
1213
@@ -788,7 +789,7 @@ export class Try<
788789 if ( this . config . debug ) {
789790 console . error ( e ) ;
790791 }
791- const error = Try . normalizeThrown ( e ) ;
792+ const error = normalizeThrown ( e ) ;
792793 this . exec . result = { success : false , error } ;
793794 return this . exec . result ;
794795 } )
@@ -809,7 +810,7 @@ export class Try<
809810 if ( this . config . debug ) {
810811 console . error ( e ) ;
811812 }
812- const error = Try . normalizeThrown ( e ) ;
813+ const error = normalizeThrown ( e ) ;
813814 this . exec . isAsync = false ;
814815 this . exec . result = { success : false , error } ;
815816 } finally {
@@ -823,10 +824,7 @@ export class Try<
823824 }
824825
825826 private static normalizeThrown ( e : unknown ) : Error {
826- if ( e instanceof Error ) return e ;
827- const wrapped = new Error ( `Non-Error thrown (${ typeof e } )` ) ;
828- wrapped . cause = e ;
829- return wrapped ;
827+ return normalizeThrown ( e ) ;
830828 }
831829
832830 private runFinallyCallback ( ) : void | Promise < void > {
Original file line number Diff line number Diff line change 55export * from './types' ;
66export * from './transformers' ;
77export * from './breadcrumbs' ;
8+ export * from './normalize' ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Normalize any thrown value into a real `Error` instance. If the value is
3+ * already an `Error`, returned unchanged. Otherwise wrapped in a fresh
4+ * `Error` whose `message` records the `typeof` and whose `cause` preserves
5+ * the original value.
6+ */
7+ export function normalizeThrown ( e : unknown ) : Error {
8+ if ( e instanceof Error ) return e ;
9+ const wrapped = new Error ( `Non-Error thrown (${ typeof e } )` ) ;
10+ wrapped . cause = e ;
11+ return wrapped ;
12+ }
Original file line number Diff line number Diff line change 11import type { BreadcrumbTransformer } from './types' ;
22import { BreadcrumbTransformationError } from './types' ;
3+ import { normalizeThrown } from './normalize' ;
34
45/**
56 * Predefined transformer functions for common use cases
@@ -61,7 +62,7 @@ export class TransformerRegistry {
6162 return transformer ( value ) ;
6263 } catch ( error ) {
6364 const transformationError = new BreadcrumbTransformationError (
64- error as Error ,
65+ normalizeThrown ( error ) ,
6566 'custom' ,
6667 ) ;
6768
@@ -87,7 +88,7 @@ export class TransformerRegistry {
8788 return transformer ( value , paramIndex ) ;
8889 } catch ( error ) {
8990 const transformationError = new BreadcrumbTransformationError (
90- error as Error ,
91+ normalizeThrown ( error ) ,
9192 transformerType ,
9293 paramIndex ,
9394 ) ;
You can’t perform that action at this time.
0 commit comments