Skip to content

Commit f6dfa7a

Browse files
committed
try
1 parent 9afd08f commit f6dfa7a

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

ui/helpers/utils/critical-startup-error-handler.ts

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class CriticalStartupErrorHandler {
3434

3535
#onLivenessCheckCompleted?: () => void;
3636

37+
#errorDisplayed = false;
38+
3739
/**
3840
* Creates an instance of CriticalStartupErrorHandler.
3941
* This class listens for critical startup errors from the background script
@@ -66,13 +68,17 @@ export class CriticalStartupErrorHandler {
6668
try {
6769
await Promise.race([livenessCheck, timeoutPromise]);
6870
} catch (error) {
69-
await displayCriticalError(
70-
this.#container,
71-
CriticalErrorTranslationKey.TroubleStarting,
72-
// This cast is safe because `livenessCheck` can't throw, and `timeoutPromise` only throws an
73-
// error.
74-
error as ErrorLike,
75-
);
71+
// Only display error if we haven't already displayed one
72+
if (!this.#errorDisplayed) {
73+
this.#errorDisplayed = true;
74+
await displayCriticalError(
75+
this.#container,
76+
CriticalErrorTranslationKey.TroubleStarting,
77+
// This cast is safe because `livenessCheck` can't throw, and `timeoutPromise` only throws an
78+
// error.
79+
error as ErrorLike,
80+
);
81+
}
7682
} finally {
7783
clearTimeout(this.#livenessCheckTimeoutId);
7884
}
@@ -101,7 +107,9 @@ export class CriticalStartupErrorHandler {
101107
if (method === BACKGROUND_LIVENESS_METHOD) {
102108
if (this.#onLivenessCheckCompleted) {
103109
this.#onLivenessCheckCompleted();
104-
} else {
110+
} else if (!this.#errorDisplayed) {
111+
// Only display error if we haven't already displayed one and liveness check wasn't initialized
112+
this.#errorDisplayed = true;
105113
await displayCriticalError(
106114
this.#container,
107115
CriticalErrorTranslationKey.TroubleStarting,
@@ -125,18 +133,22 @@ export class CriticalStartupErrorHandler {
125133
hasBackup: boolean;
126134
currentLocale?: string;
127135
};
128-
// Cancel the liveness check since we're displaying a corruption error
129-
clearTimeout(this.#livenessCheckTimeoutId);
130-
if (this.#onLivenessCheckCompleted) {
131-
this.#onLivenessCheckCompleted();
136+
// Only display error if we haven't already displayed one
137+
if (!this.#errorDisplayed) {
138+
this.#errorDisplayed = true;
139+
// Cancel the liveness check since we're displaying a corruption error
140+
clearTimeout(this.#livenessCheckTimeoutId);
141+
if (this.#onLivenessCheckCompleted) {
142+
this.#onLivenessCheckCompleted();
143+
}
144+
await displayStateCorruptionError(
145+
this.#container,
146+
this.#port,
147+
error,
148+
hasBackup,
149+
currentLocale,
150+
);
132151
}
133-
await displayStateCorruptionError(
134-
this.#container,
135-
this.#port,
136-
error,
137-
hasBackup,
138-
currentLocale,
139-
);
140152
} else if (method === DISPLAY_GENERAL_STARTUP_ERROR) {
141153
if (!hasProperty(data, 'params') || !isObject(data.params)) {
142154
log.error(
@@ -150,17 +162,21 @@ export class CriticalStartupErrorHandler {
150162
error: ErrorLike;
151163
currentLocale?: string;
152164
};
153-
// Cancel the liveness check since we're displaying a general error
154-
clearTimeout(this.#livenessCheckTimeoutId);
155-
if (this.#onLivenessCheckCompleted) {
156-
this.#onLivenessCheckCompleted();
165+
// Only display error if we haven't already displayed one
166+
if (!this.#errorDisplayed) {
167+
this.#errorDisplayed = true;
168+
// Cancel the liveness check since we're displaying a general error
169+
clearTimeout(this.#livenessCheckTimeoutId);
170+
if (this.#onLivenessCheckCompleted) {
171+
this.#onLivenessCheckCompleted();
172+
}
173+
await displayCriticalError(
174+
this.#container,
175+
CriticalErrorTranslationKey.TroubleStarting,
176+
error as ErrorLike,
177+
currentLocale,
178+
);
157179
}
158-
await displayCriticalError(
159-
this.#container,
160-
CriticalErrorTranslationKey.TroubleStarting,
161-
error as ErrorLike,
162-
currentLocale,
163-
);
164180
}
165181
};
166182

0 commit comments

Comments
 (0)