mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	blueslip_stacktrace: Handle promises in sourceCache.
Fixes “TypeError: sourceContent.split is not a function” at blueslip_stacktrace.ts:60 when there’s another error during page load. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							df5345705c
						
					
				
				
					commit
					849c7f83a0
				
			@@ -48,12 +48,12 @@ export function clean_function_name(
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const sourceCache: { [source: string]: string } = {};
 | 
					const sourceCache: { [source: string]: string | Promise<string> } = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const stack_trace_gps = new StackTraceGPS({ sourceCache });
 | 
					const stack_trace_gps = new StackTraceGPS({ sourceCache });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_context(location: StackFrame.StackFrame): NumberedLine[] | undefined {
 | 
					async function get_context(location: StackFrame.StackFrame): Promise<NumberedLine[] | undefined> {
 | 
				
			||||||
    const sourceContent = sourceCache[location.getFileName()];
 | 
					    const sourceContent = await sourceCache[location.getFileName()];
 | 
				
			||||||
    if (sourceContent === undefined) {
 | 
					    if (sourceContent === undefined) {
 | 
				
			||||||
        return undefined;
 | 
					        return undefined;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -84,7 +84,7 @@ export async function display_stacktrace(error: string, stack: string): Promise<
 | 
				
			|||||||
                show_path: clean_path(location.getFileName()),
 | 
					                show_path: clean_path(location.getFileName()),
 | 
				
			||||||
                line_number: location.getLineNumber(),
 | 
					                line_number: location.getLineNumber(),
 | 
				
			||||||
                function_name: clean_function_name(location.getFunctionName()),
 | 
					                function_name: clean_function_name(location.getFunctionName()),
 | 
				
			||||||
                context: get_context(location),
 | 
					                context: await get_context(location),
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								static/js/types/stacktrace-gps/index.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								static/js/types/stacktrace-gps/index.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -5,7 +5,7 @@ import SourceMap from "source-map";
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
declare namespace StackTraceGPS {
 | 
					declare namespace StackTraceGPS {
 | 
				
			||||||
    type StackTraceGPSOptions = {
 | 
					    type StackTraceGPSOptions = {
 | 
				
			||||||
        sourceCache?: { [url: string]: string };
 | 
					        sourceCache?: { [url: string]: string | Promise<string> };
 | 
				
			||||||
        sourceMapConsumerCache?: { [sourceMappingUrl: string]: SourceMap.SourceMapConsumer };
 | 
					        sourceMapConsumerCache?: { [sourceMappingUrl: string]: SourceMap.SourceMapConsumer };
 | 
				
			||||||
        offline?: boolean;
 | 
					        offline?: boolean;
 | 
				
			||||||
        ajax?(url: string): Promise<string>;
 | 
					        ajax?(url: string): Promise<string>;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user