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:
Anders Kaseorg
2020-02-03 15:23:38 -08:00
committed by Tim Abbott
parent df5345705c
commit 849c7f83a0
2 changed files with 5 additions and 5 deletions

View File

@@ -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 });
function get_context(location: StackFrame.StackFrame): NumberedLine[] | undefined {
const sourceContent = sourceCache[location.getFileName()];
async function get_context(location: StackFrame.StackFrame): Promise<NumberedLine[] | undefined> {
const sourceContent = await sourceCache[location.getFileName()];
if (sourceContent === undefined) {
return undefined;
}
@@ -84,7 +84,7 @@ export async function display_stacktrace(error: string, stack: string): Promise<
show_path: clean_path(location.getFileName()),
line_number: location.getLineNumber(),
function_name: clean_function_name(location.getFunctionName()),
context: get_context(location),
context: await get_context(location),
};
})
);

View File

@@ -5,7 +5,7 @@ import SourceMap from "source-map";
declare namespace StackTraceGPS {
type StackTraceGPSOptions = {
sourceCache?: { [url: string]: string };
sourceCache?: { [url: string]: string | Promise<string> };
sourceMapConsumerCache?: { [sourceMappingUrl: string]: SourceMap.SourceMapConsumer };
offline?: boolean;
ajax?(url: string): Promise<string>;