browse the protocol like its 2008 ibex.desertthunder.dev
ubuntu atproto svelte
7

Configure Feed

Select the types of activity you want to include in your feed.

refactor: create shared error utility

Owais Jamil (Jun 9, 2026, 12:38 PM -0500) c1f7bd4b 3c1e4ab2

+23 -14
+3 -6
src/lib/atproto/repo.svelte.ts
··· 1 1 import { Client, ok, simpleFetchHandler } from '@atcute/client'; 2 2 import type { ActorIdentifier, Nsid } from '@atcute/lexicons/syntax'; 3 3 import type {} from '@atcute/atproto'; 4 + import { errorMessage } from '$lib/utils/errors'; 4 5 import type { AccountIdentity } from './identity'; 5 6 6 7 export type CollectionSummary = { name: string; icon: string; loadedCount: number | null }; ··· 56 57 await this.selectCollection(identity, this.selectedCollection); 57 58 } 58 59 } catch (unknownError) { 59 - this.error = messageFromError(unknownError, 'Could not load repository collections.'); 60 + this.error = errorMessage(unknownError, 'Could not load repository collections.'); 60 61 } finally { 61 62 this.isLoadingCollections = false; 62 63 } ··· 86 87 ); 87 88 } catch (unknownError) { 88 89 this.records = []; 89 - this.error = messageFromError(unknownError, `Could not load records for ${collectionName}.`); 90 + this.error = errorMessage(unknownError, `Could not load records for ${collectionName}.`); 90 91 } finally { 91 92 this.isLoadingRecords = false; 92 93 } ··· 178 179 minute: '2-digit' 179 180 }).format(date); 180 181 } 181 - 182 - function messageFromError(error: unknown, fallback: string) { 183 - return error instanceof Error ? error.message : fallback; 184 - }
+2 -1
src/lib/components/SetupDialog.svelte
··· 1 1 <script lang="ts"> 2 2 import { resolveAccount, type AccountIdentity } from '$lib/atproto/identity'; 3 3 import { accountSetup, setupDefaults } from '$lib/atproto/setup.svelte'; 4 + import { errorMessage } from '$lib/utils/errors'; 4 5 5 6 let handle = $state(setupDefaults.handle); 6 7 let resolvedIdentity = $state<AccountIdentity | null>(null); ··· 17 18 try { 18 19 resolvedIdentity = await resolveAccount(handle); 19 20 } catch (unknownError) { 20 - error = unknownError instanceof Error ? unknownError.message : 'Could not resolve that handle.'; 21 + error = errorMessage(unknownError, 'Could not resolve that handle.'); 21 22 } finally { 22 23 isResolving = false; 23 24 }
+2 -5
src/lib/db/client.ts
··· 1 1 import { PGlite } from '@electric-sql/pglite'; 2 + import { errorMessage } from '$lib/utils/errors'; 2 3 import { resetLocalCacheDatabase } from './migrations'; 3 4 import { DB_DATA_DIR, SQL } from './schema'; 4 5 ··· 83 84 status: 'error', 84 85 finishedAt: new Date().toISOString(), 85 86 wasm: 'error', 86 - error: messageFromError(error) 87 + error: errorMessage(error) 87 88 }; 88 89 databasePromise = null; 89 90 throw error; ··· 115 116 error: null 116 117 }; 117 118 } 118 - 119 - function messageFromError(error: unknown) { 120 - return error instanceof Error ? error.message : String(error); 121 - }
+13
src/lib/utils/errors.ts
··· 1 + /** 2 + * 3 + * Extracts the error message from an error object, or returns a fallback string 4 + * if the error is not an instance of Error. 5 + * 6 + * @param err 7 + * @param fallback 8 + * @returns an error message, object as string, or fallback 9 + */ 10 + export function errorMessage(err: unknown, fallback?: string): string { 11 + const message = fallback ?? String(err); 12 + return err instanceof Error ? err.message : message; 13 + }
+3 -2
src/routes/+layout.svelte
··· 5 5 import { accountSetup } from '$lib/atproto/setup.svelte'; 6 6 import favicon from '$lib/assets/favicon.svg'; 7 7 import { getDatabase, resetLocalDatabase, runMigrations } from '$lib/db'; 8 + import { errorMessage } from '$lib/utils/errors'; 8 9 import { windowManager } from '$lib/window-manager.svelte'; 9 10 import AboutComputer from '$lib/components/AboutComputer.svelte'; 10 11 import AppWindow from '$lib/components/AppWindow.svelte'; ··· 92 93 accountSetup.load(); 93 94 bootStatus = 'ready'; 94 95 } catch (error) { 95 - bootError = error instanceof Error ? error.message : 'Could not start the local cache.'; 96 + bootError = errorMessage(error, 'Could not start the local cache.'); 96 97 bootStatus = 'error'; 97 98 } 98 99 } ··· 106 107 await resetLocalDatabase(); 107 108 await bootDesktop(); 108 109 } catch (error) { 109 - bootError = error instanceof Error ? error.message : 'Could not reset the local cache.'; 110 + bootError = errorMessage(error, 'Could not reset the local cache.'); 110 111 bootStatus = 'error'; 111 112 } 112 113 }