mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	sentry: Always capture an Error, rather than a string.
We pass the original exception down as the `cause`, if present. This makes Sentry properly capture the callstack.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							9d6ca32c59
						
					
				
				
					commit
					fea5a3fdb8
				
			@@ -102,19 +102,14 @@ export function error(
 | 
			
		||||
    more_info?: object | undefined,
 | 
			
		||||
    original_error?: unknown | undefined,
 | 
			
		||||
): void {
 | 
			
		||||
    // original_error could be of any type, because you can "raise"
 | 
			
		||||
    // any type -- something we do see in practice with the error
 | 
			
		||||
    // object being "dead": https://github.com/zulip/zulip/issues/18374
 | 
			
		||||
    let exception: string | Error = msg;
 | 
			
		||||
    if (original_error !== undefined && original_error instanceof Error) {
 | 
			
		||||
        original_error.message = msg;
 | 
			
		||||
        exception = original_error;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Log the Sentry error before the console warning, so we don't
 | 
			
		||||
    // end up with a doubled message in the Sentry logs.
 | 
			
		||||
    Sentry.setContext("more_info", more_info === undefined ? null : more_info);
 | 
			
		||||
    Sentry.getCurrentHub().captureException(exception);
 | 
			
		||||
 | 
			
		||||
    // Note that original_error could be of any type, because you can "raise"
 | 
			
		||||
    // any type -- something we do see in practice with the error
 | 
			
		||||
    // object being "dead": https://github.com/zulip/zulip/issues/18374
 | 
			
		||||
    Sentry.getCurrentHub().captureException(new Error(msg, {cause: original_error}));
 | 
			
		||||
 | 
			
		||||
    const args = build_arg_list(msg, more_info);
 | 
			
		||||
    logger.error(...args);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user