Skip to content

Commit e98e8da

Browse files
authored
Merge pull request #9875 from gitbutlerapp/refactor-log-to-backend
Move logErrorToFile to backend module
2 parents 66ffdf3 + 73bcb2a commit e98e8da

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

apps/desktop/src/hooks.client.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { logErrorToFile } from '$lib/backend';
12
import { SilentError } from '$lib/error/error';
23
import { showError } from '$lib/notifications/toasts';
34
import { captureException } from '@sentry/sveltekit';
4-
import { error as logErrorToFile } from '@tauri-apps/plugin-log';
55
import type { HandleClientError } from '@sveltejs/kit';
66

77
// SvelteKit error handler.
@@ -61,13 +61,10 @@ function logError(error: unknown) {
6161
showError('Unhandled exception', error);
6262
}
6363

64+
const logMessage = loggableError(error);
65+
logErrorToFile(logMessage);
66+
6467
console.error(error);
65-
if (import.meta.env.VITE_BUILD_TARGET === 'web') {
66-
// TODO: Replace with electron log file
67-
} else {
68-
const errorMessage = loggableError(error);
69-
logErrorToFile(errorMessage);
70-
}
7168
} catch (err: unknown) {
7269
console.error('Error while trying to log error.', err);
7370
}

apps/desktop/src/lib/backend/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Tauri, { tauriPathSeparator } from '$lib/backend/tauri';
2-
import Web, { webPathSeparator } from '$lib/backend/web';
1+
import Tauri, { tauriLogErrorToFile, tauriPathSeparator } from '$lib/backend/tauri';
2+
import Web, { webLogErrorToFile, webPathSeparator } from '$lib/backend/web';
33
import { InjectionToken } from '@gitbutler/shared/context';
44
import type { IBackend } from '$lib/backend/backend';
55

@@ -27,4 +27,13 @@ export function platformPathSeparator(): string {
2727
return tauriPathSeparator();
2828
}
2929

30+
export function logErrorToFile(error: string) {
31+
if (import.meta.env.VITE_BUILD_TARGET === 'web') {
32+
webLogErrorToFile(error);
33+
return;
34+
}
35+
36+
tauriLogErrorToFile(error);
37+
}
38+
3039
export * from '$lib/backend/backend';

apps/desktop/src/lib/backend/tauri.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@tauri-apps/plugin-clipboard-manager';
1212
import { open as filePickerTauri, type OpenDialogOptions } from '@tauri-apps/plugin-dialog';
1313
import { readFile as tauriReadFile } from '@tauri-apps/plugin-fs';
14+
import { error as logErrorToFile } from '@tauri-apps/plugin-log';
1415
import { platform } from '@tauri-apps/plugin-os';
1516
import { relaunch as relaunchTauri } from '@tauri-apps/plugin-process';
1617
import { Store } from '@tauri-apps/plugin-store';
@@ -75,6 +76,10 @@ class TauriDiskStore implements DiskStore {
7576
}
7677
}
7778

79+
export async function tauriLogErrorToFile(error: string) {
80+
await logErrorToFile(error);
81+
}
82+
7883
export function tauriPathSeparator(): string {
7984
const platformName = platform();
8085
return platformName === 'windows' ? '\\' : '/';

apps/desktop/src/lib/backend/web.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class WebDiskStore implements DiskStore {
5252
}
5353
}
5454

55+
export function webLogErrorToFile(error: string) {
56+
// TODO: Implement this for the web version if needed
57+
console.error('Logging to file is not supported in web builds.');
58+
console.error(error);
59+
}
5560
export function webPathSeparator(): string {
5661
return '/'; // Web uses forward slashes for path
5762
}

0 commit comments

Comments
 (0)