Skip to content

Commit b038f16

Browse files
committed
change(debug): Allow keyed runtime issues to reduce clutter
1 parent cf5e666 commit b038f16

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

libs/server/debugging.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,30 @@ import Logger = pino.Logger;
88

99
export * from 'libs/shared/debugging'; // here's a lil' lesson in trickery
1010

11-
const runtimeIssues: Array<Issue> = [];
11+
const serialRuntimeIssues: Array<Issue> = [];
12+
const keyedRuntimeIssues: Record<keyof any, Issue | undefined> = {};
1213
export function reportRuntimeIssue(issue: Issue) {
13-
runtimeIssues.push({
14+
const complete = {
1415
...issue,
1516
isRuntime: true
17+
};
18+
serialRuntimeIssues.push(complete);
19+
}
20+
export function setKeyedRuntimeIssue(key: keyof typeof keyedRuntimeIssues, issue: Issue | null) {
21+
if (issue === null) {
22+
delete keyedRuntimeIssues[key];
23+
} else {
24+
keyedRuntimeIssues[key] = issue;
25+
}
26+
}
27+
function getAllKeyedRuntimeIssues(): Array<Issue> {
28+
const values: Array<Issue> = [];
29+
Object.values(keyedRuntimeIssues).forEach((v) => {
30+
if (v != undefined) { // non-strict equality because that's better for null checks
31+
values.push(v);
32+
}
1633
});
34+
return values;
1735
}
1836

1937
export function findIssues(): Array<Issue> {
@@ -32,7 +50,7 @@ export function findIssues(): Array<Issue> {
3250
});
3351
}
3452

35-
issues.push(...runtimeIssues);
53+
issues.push(...serialRuntimeIssues, ...getAllKeyedRuntimeIssues());
3654

3755
return issues;
3856
}

pages/api/settings.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import {
1111
IssueCategory,
1212
IssueFixRecommendation,
1313
IssueSeverity,
14-
reportRuntimeIssue
14+
setKeyedRuntimeIssue
1515
} from 'libs/server/debugging';
1616

17+
const SYM_ISSUE_CANNOT_GET_SETTINGS = Symbol();
1718
export async function getSettings(store: StoreProvider): Promise<Settings> {
1819
const settingsPath = getPathSettings();
1920
let settings;
@@ -24,7 +25,7 @@ export async function getSettings(store: StoreProvider): Promise<Settings> {
2425
);
2526
}
2627
} catch (e) {
27-
reportRuntimeIssue({
28+
setKeyedRuntimeIssue(SYM_ISSUE_CANNOT_GET_SETTINGS, {
2829
category: IssueCategory.STORE,
2930
severity: IssueSeverity.FATAL_ERROR,
3031
name: "Could not get settings",
@@ -38,6 +39,7 @@ export async function getSettings(store: StoreProvider): Promise<Settings> {
3839
});
3940
throw e;
4041
}
42+
setKeyedRuntimeIssue(SYM_ISSUE_CANNOT_GET_SETTINGS, null); // if no issue is there, it removes the issue
4143
const formatted = formatSettings(settings || {});
4244

4345
if (!settings || !isEqual(settings, formatted)) {

0 commit comments

Comments
 (0)