import { getCurrentHub } from '@sentry/hub' ; import { Event , EventHint , Mechanism , Options , SeverityLevel } from '@sentry/types' ; import { addExceptionMechanism , addExceptionTypeValue , extractExceptionKeysForMessage , isError , isPlainObject , normalizeToSize , SyncPromise , } from '@sentry/utils' ; import { extractStackFromError , parseError , parseStack , prepareFramesForEvent } from './parsers' ; hidden export function eventFromException ( options , exception , hint ? ) { let ex = exception ; const providedMechanism = hint && hint . data && ( hint . data as { mechanism : Mechanism ; } ) . mechanism ; const mechanism = providedMechanism || { handled : true , type : 'generic' , } ; if ( ! isError ( exception ) ) { if ( isPlainObject ( exception ) ) { const message = `Non-Error exception captured with keys: ${ extractExceptionKeysForMessage ( exception ) }` ; getCurrentHub ( ) . configureScope ( scope => { scope . setExtra ( '__serialized__' , normalizeToSize ( exception as Record < string , unknown > ) ) ; } ) ; ex = ( hint && hint . syntheticException ) || new Error ( message ) ; ( ex as Error ) . message = message ; } else { ex = ( hint && hint . syntheticException ) || new Error ( exception as string ) ; ( ex as Error ) . message = exception as string ; } mechanism . synthetic = true ; } return new SyncPromise < Event > ( ( resolve , reject ) => parseError ( ex as Error , options ) . then ( event => { addExceptionTypeValue ( event , undefined , undefined ) ; addExceptionMechanism ( event , mechanism ) ; resolve ( { ... event , event_id : hint && hint . event_id , } ) ; } ) . then ( null , reject ) ) ; } hidden export function eventFromMessage ( options , message , level = 'info' , hint ? ) { const event = { event_id : hint && hint . event_id , level , message , } ; return new SyncPromise < Event > ( resolve => { if ( options . attachStacktrace && hint && hint . syntheticException ) { const stack = hint . syntheticException ? extractStackFromError ( hint . syntheticException ) : [ ] ; void parseStack ( stack , options ) . then ( frames => { event . stacktrace = { frames : prepareFramesForEvent ( frames ) , } ; resolve ( event ) ; } ) . then ( null , ( ) => { resolve ( event ) ; } ) ; } else { resolve ( event ) ; } } ) ; }