Skip to content

Commit

Permalink
change(debug): Allow keyed runtime issues to reduce clutter
Browse files Browse the repository at this point in the history
  • Loading branch information
tecc committed Nov 11, 2022
1 parent cf5e666 commit b038f16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
24 changes: 21 additions & 3 deletions libs/server/debugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@ import Logger = pino.Logger;

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

const runtimeIssues: Array<Issue> = [];
const serialRuntimeIssues: Array<Issue> = [];
const keyedRuntimeIssues: Record<keyof any, Issue | undefined> = {};
export function reportRuntimeIssue(issue: Issue) {
runtimeIssues.push({
const complete = {
...issue,
isRuntime: true
};
serialRuntimeIssues.push(complete);
}
export function setKeyedRuntimeIssue(key: keyof typeof keyedRuntimeIssues, issue: Issue | null) {
if (issue === null) {
delete keyedRuntimeIssues[key];
} else {
keyedRuntimeIssues[key] = issue;
}
}
function getAllKeyedRuntimeIssues(): Array<Issue> {
const values: Array<Issue> = [];
Object.values(keyedRuntimeIssues).forEach((v) => {
if (v != undefined) { // non-strict equality because that's better for null checks
values.push(v);
}
});
return values;
}

export function findIssues(): Array<Issue> {
Expand All @@ -32,7 +50,7 @@ export function findIssues(): Array<Issue> {
});
}

issues.push(...runtimeIssues);
issues.push(...serialRuntimeIssues, ...getAllKeyedRuntimeIssues());

return issues;
}
Expand Down
6 changes: 4 additions & 2 deletions pages/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
IssueCategory,
IssueFixRecommendation,
IssueSeverity,
reportRuntimeIssue
setKeyedRuntimeIssue
} from 'libs/server/debugging';

const SYM_ISSUE_CANNOT_GET_SETTINGS = Symbol();
export async function getSettings(store: StoreProvider): Promise<Settings> {
const settingsPath = getPathSettings();
let settings;
Expand All @@ -24,7 +25,7 @@ export async function getSettings(store: StoreProvider): Promise<Settings> {
);
}
} catch (e) {
reportRuntimeIssue({
setKeyedRuntimeIssue(SYM_ISSUE_CANNOT_GET_SETTINGS, {
category: IssueCategory.STORE,
severity: IssueSeverity.FATAL_ERROR,
name: "Could not get settings",
Expand All @@ -38,6 +39,7 @@ export async function getSettings(store: StoreProvider): Promise<Settings> {
});
throw e;
}
setKeyedRuntimeIssue(SYM_ISSUE_CANNOT_GET_SETTINGS, null); // if no issue is there, it removes the issue
const formatted = formatSettings(settings || {});

if (!settings || !isEqual(settings, formatted)) {
Expand Down

0 comments on commit b038f16

Please sign in to comment.