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: Pass the Error around, rather than re-creating a dummy one.

Alex Vandiver7898818983c2
diff --git a/web/src/blueslip.ts b/web/src/blueslip.ts
index b39586b47ce..5a27f97b1d5 100644
--- a/web/src/blueslip.ts
+++ b/web/src/blueslip.ts
@@ -122,23 +122,6 @@ export function error(
// fatal error even in production, use throw new Error(…) instead.
}
-export function exception_msg(
- ex: Error & {
- // Unsupported properties available on some browsers
- fileName?: string;
- lineNumber?: number;
- },
-): string {
- let message = ex.message;
- if (ex.fileName !== undefined) {
- message += " at " + ex.fileName;
- if (ex.lineNumber !== undefined) {
- message += `:${ex.lineNumber}`;
- }
- }
- return message;
-}
-
// Install a window-wide onerror handler in development to display the stacktraces, to make them
// hard to miss
if (page_params.development_environment) {
@@ -153,6 +136,6 @@ if (page_params.development_environment) {
return;
}
- void blueslip_stacktrace.display_stacktrace(exception_msg(ex), ex.stack);
+ void blueslip_stacktrace.display_stacktrace(ex);
});
}
diff --git a/web/src/blueslip_stacktrace.ts b/web/src/blueslip_stacktrace.ts
index b0a7a221644..5ecfcb0cf49 100644
--- a/web/src/blueslip_stacktrace.ts
+++ b/web/src/blueslip_stacktrace.ts
@@ -24,6 +24,23 @@ type CleanStackFrame = {
context?: NumberedLine[];
};
+export function exception_msg(
+ ex: Error & {
+ // Unsupported properties available on some browsers
+ fileName?: string;
+ lineNumber?: number;
+ },
+): string {
+ let message = ex.message;
+ if (ex.fileName !== undefined) {
+ message += " at " + ex.fileName;
+ if (ex.lineNumber !== undefined) {
+ message += `:${ex.lineNumber}`;
+ }
+ }
+ return message;
+}
+
export function clean_path(full_path?: string): string | undefined {
// If the file is local, just show the filename.
// Otherwise, show the full path starting from node_modules.
@@ -81,10 +98,7 @@ async function get_context(location: StackFrame): Promise<NumberedLine[] | undef
}));
}
-export async function display_stacktrace(error: string, stack: string): Promise<void> {
- const ex = new Error("dummy");
- ex.stack = stack;
-
+export async function display_stacktrace(ex: Error): Promise<void> {
const stackframes: CleanStackFrame[] = await Promise.all(
ErrorStackParser.parse(ex).map(async (location: StackFrame) => {
try {
@@ -104,7 +118,12 @@ export async function display_stacktrace(error: string, stack: string): Promise<
const $alert = $("<div>")
.addClass("stacktrace")
- .html(render_blueslip_stacktrace({error, stackframes}));
+ .html(
+ render_blueslip_stacktrace({
+ error: exception_msg(ex),
+ stackframes,
+ }),
+ );
$(".alert-box").append($alert);
$alert.addClass("show");
}