Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

blueslip: Show popups for thrown non-Error values in development.

Anders Kaseorg148af2a30134
diff --git a/web/src/blueslip.ts b/web/src/blueslip.ts
index 7e407cfb837..825c946c6af 100644
--- a/web/src/blueslip.ts
+++ b/web/src/blueslip.ts
@@ -111,7 +111,7 @@ export function error(msg: string, more_info?: object | undefined, original_erro
if (DEVELOPMENT) {
$(window).on("error", (event: JQuery.TriggeredEvent) => {
const {originalEvent} = event;
- if (originalEvent instanceof ErrorEvent && originalEvent.error instanceof Error) {
+ if (originalEvent instanceof ErrorEvent) {
void display_stacktrace(originalEvent.error);
}
});
diff --git a/web/src/blueslip_stacktrace.ts b/web/src/blueslip_stacktrace.ts
index 57caa071964..4f894fdbc63 100644
--- a/web/src/blueslip_stacktrace.ts
+++ b/web/src/blueslip_stacktrace.ts
@@ -109,41 +109,54 @@ async function get_context(location: StackFrame): Promise<NumberedLine[] | undef
}));
}
-export async function display_stacktrace(ex: Error): Promise<void> {
+export async function display_stacktrace(ex: unknown): Promise<void> {
const errors = [];
- while (true) {
- const stackframes: CleanStackFrame[] = await Promise.all(
- ErrorStackParser.parse(ex).map(async (location: StackFrame) => {
- try {
- location = await stack_trace_gps.getMappedLocation(location);
- } catch {
- // Use unmapped location
- }
- return {
- full_path: location.getFileName(),
- show_path: clean_path(location.getFileName()),
- line_number: location.getLineNumber(),
- function_name: clean_function_name(location.getFunctionName()),
- context: await get_context(location),
- };
- }),
- );
+ do {
+ if (!(ex instanceof Error)) {
+ const prototype: unknown = Object.getPrototypeOf(ex);
+ errors.push({
+ name:
+ typeof prototype === "object" &&
+ prototype !== null &&
+ "constructor" in prototype
+ ? `thrown ${prototype.constructor.name}`
+ : "thrown",
+ message: String(ex),
+ stackframes: [],
+ });
+ break;
+ }
+ const stackframes: CleanStackFrame[] =
+ ex instanceof Error
+ ? await Promise.all(
+ ErrorStackParser.parse(ex).map(async (location: StackFrame) => {
+ try {
+ location = await stack_trace_gps.getMappedLocation(location);
+ } catch {
+ // Use unmapped location
+ }
+ return {
+ full_path: location.getFileName(),
+ show_path: clean_path(location.getFileName()),
+ line_number: location.getLineNumber(),
+ function_name: clean_function_name(location.getFunctionName()),
+ context: await get_context(location),
+ };
+ }),
+ )
+ : [];
let more_info: string | undefined;
if (ex instanceof BlueslipError) {
more_info = JSON.stringify(ex.more_info, null, 4);
}
errors.push({
+ name: ex.name,
message: exception_msg(ex),
more_info,
stackframes,
});
-
- if (ex.cause !== undefined && ex.cause instanceof Error) {
- ex = ex.cause;
- } else {
- break;
- }
- }
+ ex = ex.cause;
+ } while (ex !== undefined);
const $alert = $("<div>").addClass("stacktrace").html(render_blueslip_stacktrace({errors}));
$(".alert-box").append($alert);
diff --git a/web/templates/blueslip_stacktrace.hbs b/web/templates/blueslip_stacktrace.hbs
index 04c73c3b416..0ee27e64271 100644
--- a/web/templates/blueslip_stacktrace.hbs
+++ b/web/templates/blueslip_stacktrace.hbs
@@ -3,7 +3,7 @@
<div class="warning-symbol">
<i class="fa fa-exclamation-triangle"></i>
</div>
- <div class="message"><strong>Error:</strong> {{ message }}</div>
+ <div class="message">{{#unless @first}}caused by {{/unless}}<strong>{{name}}:</strong> {{ message }}</div>
{{#if @first}}
<div class="exit"></div>
{{/if}}