Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error handling ergonomics #3898

Merged
merged 14 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions app/src/lib/backend/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import type { EventCallback, EventName } from '@tauri-apps/api/event';
export enum Code {
Unknown = 'errors.unknown',
Validation = 'errors.validation',
Projects = 'errors.projects',
ProjectsGitAuth = 'errors.projects.git.auth',
ProjectsGitRemote = 'errors.projects.git.remote',
ProjectHead = 'errors.projects.head',
ProjectConflict = 'errors.projects.conflict'
ProjectsGitAuth = 'errors.projects.git.auth'
}

export class UserError extends Error {
Expand All @@ -26,10 +22,17 @@ export class UserError extends Error {
const cause = error instanceof Error ? error : undefined;
const code = error.code ?? Code.Unknown;
const message = error.message ?? error;
return new UserError(message, code, cause);
return new UserError(capitalize(message), code, cause);
}
}

function capitalize(str: string): string {
if (str.length === 0) {
return str;
}
return str.charAt(0).toUpperCase() + str.slice(1);
}

export async function invoke<T>(command: string, params: Record<string, unknown> = {}): Promise<T> {
// This commented out code can be used to delay/reject an api call
// return new Promise<T>((resolve, reject) => {
Expand Down
Loading
Loading