Skip to content

Commit 400a788

Browse files
committed
refactor: choose some more expressive names in errorHandling.ts
1 parent a8a327a commit 400a788

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/ElectronBackend/errorHandling/errorHandling.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getGlobalBackendState } from '../main/globalBackendState';
1717
import logger from '../main/logger';
1818
import { getLoadedFilePath } from '../utils/getLoadedFile';
1919

20-
async function reportListenerErrorInBackend(
20+
async function showListenerErrorInMessageBox(
2121
mainWindow: BrowserWindow,
2222
error: unknown,
2323
): Promise<void> {
@@ -40,17 +40,18 @@ async function reportListenerErrorInBackend(
4040
}
4141
}
4242

43-
function reportListenerErrorInFrontend(_: BrowserWindow, error: unknown): void {
43+
function sendListenerErrorToFrontend(_: BrowserWindow, error: unknown): void {
44+
// NOTE: these log messages are forwarded to the frontend
4445
if (error instanceof Error) {
4546
logger.error(error.message);
4647
} else {
4748
logger.error('Unexpected internal error');
4849
}
4950
}
5051

51-
export const ListenerErrorReporter = {
52-
Backend: reportListenerErrorInBackend,
53-
Frontend: reportListenerErrorInFrontend,
52+
export const ListenerErrorReporting = {
53+
ShowMessageBox: showListenerErrorInMessageBox,
54+
SendToFrontend: sendListenerErrorToFrontend,
5455
};
5556

5657
type FuncType<T> = T extends (...args: infer P) => infer R
@@ -68,7 +69,7 @@ export function createVoidListenerCallbackWithErrorHandling<F>(
6869
reportError: (
6970
mainWindow: BrowserWindow,
7071
error: unknown,
71-
) => Promise<void> | void = reportListenerErrorInBackend,
72+
) => Promise<void> | void = showListenerErrorInMessageBox,
7273
): (...args: FTParameters<F>) => Promise<void> {
7374
return async (...args: FTParameters<F>): Promise<void> => {
7475
try {
@@ -86,7 +87,7 @@ export function createListenerCallbackWithErrorHandling<F>(
8687
reportError: (
8788
mainWindow: BrowserWindow,
8889
error: unknown,
89-
) => Promise<void> | void = reportListenerErrorInBackend,
90+
) => Promise<void> | void = showListenerErrorInMessageBox,
9091
): (...args: FTParameters<F>) => Promise<ReturnTypeWithoutPromise<F>> {
9192
return async (
9293
...args: FTParameters<F>

src/ElectronBackend/main/__tests__/listeners.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ describe('getImportFileSelectSaveLocationListener', () => {
508508
expect(returnedFilePath).toBe(selectedFilePath);
509509
});
510510

511-
it('returns null when no save location was selected', async () => {
511+
it('returns an empty string when no save location was selected', async () => {
512512
const mainWindow = await initWindowAndBackendState();
513513

514514
const listener = getImportFileSelectSaveLocationListener(mainWindow);

src/ElectronBackend/main/listeners.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { LoadedFileFormat } from '../enums/enums';
2929
import {
3030
createListenerCallbackWithErrorHandling,
3131
createVoidListenerCallbackWithErrorHandling,
32-
ListenerErrorReporter,
32+
ListenerErrorReporting,
3333
} from '../errorHandling/errorHandling';
3434
import { loadInputAndOutputFromFilePath } from '../input/importFromFile';
3535
import { serializeAttributions } from '../input/parseInputData';
@@ -236,7 +236,7 @@ export function getImportFileConvertAndLoadListener(
236236

237237
return true;
238238
},
239-
ListenerErrorReporter.Frontend,
239+
ListenerErrorReporting.SendToFrontend,
240240
);
241241
}
242242

0 commit comments

Comments
 (0)