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: Support nested Error objects by .cause.

Alex Vandiverfa92895731a3
diff --git a/web/src/blueslip_stacktrace.ts b/web/src/blueslip_stacktrace.ts
index dace45f6a31..f355ded4929 100644
--- a/web/src/blueslip_stacktrace.ts
+++ b/web/src/blueslip_stacktrace.ts
@@ -110,31 +110,37 @@ async function get_context(location: StackFrame): Promise<NumberedLine[] | undef
}
export async function display_stacktrace(ex: Error): Promise<void> {
- 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),
- };
- }),
- );
-
- const $alert = $("<div>")
- .addClass("stacktrace")
- .html(
- render_blueslip_stacktrace({
- error: exception_msg(ex),
- stackframes,
+ 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),
+ };
}),
);
+ errors.push({
+ message: exception_msg(ex),
+ stackframes,
+ });
+
+ if (ex.cause !== undefined && ex.cause instanceof Error) {
+ ex = ex.cause;
+ } else {
+ break;
+ }
+ }
+
+ const $alert = $("<div>").addClass("stacktrace").html(render_blueslip_stacktrace({errors}));
$(".alert-box").append($alert);
$alert.addClass("show");
}
diff --git a/web/styles/alerts.css b/web/styles/alerts.css
index 729550a3bfa..920d1e0bd24 100644
--- a/web/styles/alerts.css
+++ b/web/styles/alerts.css
@@ -56,6 +56,7 @@ $alert-error-red: hsl(0deg 80% 40%);
.stacktrace-header {
display: flex;
justify-content: space-between;
+ align-items: center;
.message {
flex: 1 1 auto;
@@ -72,6 +73,7 @@ $alert-error-red: hsl(0deg 80% 40%);
cursor: pointer;
font-size: 2.3rem;
content: "\d7";
+ line-height: 0.5;
}
}
@@ -79,7 +81,7 @@ $alert-error-red: hsl(0deg 80% 40%);
font-family: "Source Code Pro", monospace;
font-size: 0.85rem;
- margin-top: 1rem;
+ margin-bottom: 0.5rem;
.stackframe {
padding-left: calc(3.3rem - 14px);
diff --git a/web/templates/blueslip_stacktrace.hbs b/web/templates/blueslip_stacktrace.hbs
index 22833f81378..e5cf24b4976 100644
--- a/web/templates/blueslip_stacktrace.hbs
+++ b/web/templates/blueslip_stacktrace.hbs
@@ -1,28 +1,32 @@
-<div class="stacktrace-header">
- <div class="warning-symbol">
- <i class="fa fa-exclamation-triangle"></i>
+{{#each errors}}
+ <div class="stacktrace-header">
+ <div class="warning-symbol">
+ <i class="fa fa-exclamation-triangle"></i>
+ </div>
+ <div class="message"><strong>Error:</strong> {{ message }}</div>
+ {{#if @first}}
+ <div class="exit"></div>
+ {{/if}}
</div>
- <div class="message"><strong>Error:</strong> {{ error }}</div>
- <div class="exit"></div>
-</div>
-<div class="stacktrace-content">
- {{#each stackframes}}
- <div data-full-path="{{ full_path }}" data-line-no="{{ line_number }}">
- <div class="stackframe">
- <i class="fa fa-caret-right expand"></i>
- <span class="subtle">at</span>
- {{#if function_name}}
- {{ function_name.scope }}<b>{{ function_name.name }}</b>
- {{/if}}
- <span class="subtle">{{ show_path }}:{{ line_number }}</span>
- </div>
- <div class="code-context" style="display: none">
- <div class="code-context-content">
- {{~#each context~}}
- <div {{#if focus}}class="focus-line"{{/if}}><span class="line-number">{{ line_number }}</span> {{ line }}</div>
- {{~/each~}}
+ <div class="stacktrace-content">
+ {{#each stackframes}}
+ <div data-full-path="{{ full_path }}" data-line-no="{{ line_number }}">
+ <div class="stackframe">
+ <i class="fa fa-caret-right expand"></i>
+ <span class="subtle">at</span>
+ {{#if function_name}}
+ {{ function_name.scope }}<b>{{ function_name.name }}</b>
+ {{/if}}
+ <span class="subtle">{{ show_path }}:{{ line_number }}</span>
+ </div>
+ <div class="code-context" style="display: none">
+ <div class="code-context-content">
+ {{~#each context~}}
+ <div {{#if focus}}class="focus-line"{{/if}}><span class="line-number">{{ line_number }}</span> {{ line }}</div>
+ {{~/each~}}
+ </div>
</div>
</div>
- </div>
- {{/each}}
-</div>
+ {{/each}}
+ </div>
+{{/each}}