From 150acb0abfbd71cac6042f368015e54f75e3e9ba Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Thu, 11 Apr 2024 20:01:58 +0200 Subject: [PATCH] Show most errors using toast - does not automatically dismiss - shows the error to the user --- app/src/lib/backend/projects.ts | 3 +- app/src/lib/components/BranchCard.svelte | 4 +- app/src/lib/components/BranchHeader.svelte | 17 +++---- app/src/lib/components/CommitDialog.svelte | 8 ++-- app/src/lib/components/KeysForm.svelte | 4 +- app/src/lib/components/Login.svelte | 4 +- .../components/NotOnGitButlerBranch.svelte | 7 +-- app/src/lib/components/PassphraseBox.svelte | 4 +- .../lib/components/ProblemLoadingRepo.svelte | 7 +-- .../lib/components/UpdateBaseButton.svelte | 6 +-- app/src/lib/github/service.ts | 4 +- app/src/lib/notifications/toasts.ts | 7 +++ app/src/lib/stores/remoteBranches.ts | 4 +- app/src/lib/vbranches/baseBranch.ts | 6 +-- app/src/lib/vbranches/branchController.ts | 48 +++++++++---------- .../routes/[projectId]/settings/+page.svelte | 3 +- app/src/routes/settings/profile/+page.svelte | 9 ++-- 17 files changed, 77 insertions(+), 68 deletions(-) diff --git a/app/src/lib/backend/projects.ts b/app/src/lib/backend/projects.ts index 576f3a401..c337099a2 100644 --- a/app/src/lib/backend/projects.ts +++ b/app/src/lib/backend/projects.ts @@ -1,4 +1,5 @@ import { invoke } from '$lib/backend/ipc'; +import { showError } from '$lib/notifications/toasts'; import { persisted } from '$lib/persisted/persisted'; import { observableToStore } from '$lib/rxjs/store'; import * as toasts from '$lib/utils/toasts'; @@ -115,7 +116,7 @@ export class ProjectService { // linkProjectModal?.show(project.id); goto(`/${project.id}/board`); }) - .catch((e: any) => toasts.error(e.message)); + .catch((e: any) => showError('There was a problem', e.message)); } getLastOpenedProject() { diff --git a/app/src/lib/components/BranchCard.svelte b/app/src/lib/components/BranchCard.svelte index 36f9ec161..617b528a3 100644 --- a/app/src/lib/components/BranchCard.svelte +++ b/app/src/lib/components/BranchCard.svelte @@ -21,12 +21,12 @@ DraggableRemoteCommit } from '$lib/dragging/draggables'; import { dropzone } from '$lib/dragging/dropzone'; + import { showError } from '$lib/notifications/toasts'; import { persisted } from '$lib/persisted/persisted'; import { SETTINGS, type Settings } from '$lib/settings/userSettings'; import { User } from '$lib/stores/user'; import { getContext, getContextStore, getContextStoreBySymbol } from '$lib/utils/context'; import { computeAddedRemovedByFiles } from '$lib/utils/metrics'; - import * as toasts from '$lib/utils/toasts'; import { BranchController } from '$lib/vbranches/branchController'; import { FileIdSelection } from '$lib/vbranches/fileIdSelection'; import { filesToOwnership } from '$lib/vbranches/ownership'; @@ -84,7 +84,7 @@ } } catch (e) { console.error(e); - toasts.error('Failed to generate branch name'); + showError('Failed to generate branch name', e); } } diff --git a/app/src/lib/components/BranchHeader.svelte b/app/src/lib/components/BranchHeader.svelte index b9c3195b2..c8520ea5d 100644 --- a/app/src/lib/components/BranchHeader.svelte +++ b/app/src/lib/components/BranchHeader.svelte @@ -7,11 +7,10 @@ import { clickOutside } from '$lib/clickOutside'; import Button from '$lib/components/Button.svelte'; import Icon from '$lib/components/Icon.svelte'; + import { showError } from '$lib/notifications/toasts'; import { getContext, getContextStore } from '$lib/utils/context'; - import * as toasts from '$lib/utils/toasts'; import { BranchController } from '$lib/vbranches/branchController'; import { Branch } from '$lib/vbranches/types'; - import toast from 'svelte-french-toast'; import type { Persisted } from '$lib/persisted/persisted'; import { goto } from '$app/navigation'; @@ -157,10 +156,9 @@ try { await branchController.deleteBranch(branch.id); goto(`/${project.id}/board`); - } catch (e) { - const err = 'Failed to delete branch'; - toasts.error(err); - console.error(err, e); + } catch (err) { + showError('Failed to delete branch', err); + console.error(err); } finally { isDeleting = false; } @@ -179,10 +177,9 @@ try { await branchController.applyBranch(branch.id); goto(`/${project.id}/board`); - } catch (e) { - const err = 'Failed to apply branch'; - toast.error(err); - console.error(err, e); + } catch (err) { + showError('Failed to apply branch', err); + console.error(err); } finally { isApplying = false; } diff --git a/app/src/lib/components/CommitDialog.svelte b/app/src/lib/components/CommitDialog.svelte index 0728f13f3..284603f67 100644 --- a/app/src/lib/components/CommitDialog.svelte +++ b/app/src/lib/components/CommitDialog.svelte @@ -14,10 +14,10 @@ projectRunCommitHooks, persistedCommitMessage } from '$lib/config/config'; + import { showError } from '$lib/notifications/toasts'; import { User } from '$lib/stores/user'; import { splitMessage } from '$lib/utils/commitMessage'; import { getContext, getContextStore } from '$lib/utils/context'; - import * as toasts from '$lib/utils/toasts'; import { tooltip } from '$lib/utils/tooltip'; import { setAutoHeight } from '$lib/utils/useAutoHeight'; import { useResize } from '$lib/utils/useResize'; @@ -113,10 +113,10 @@ if (generatedMessage) { $commitMessage = generatedMessage; } else { - toasts.error('Failed to generate commit message'); + throw new Error('Prompt generated no response'); } - } catch { - toasts.error('Failed to generate commit message'); + } catch (e: any) { + showError('Failed to generate commit message', e); } finally { aiLoading = false; } diff --git a/app/src/lib/components/KeysForm.svelte b/app/src/lib/components/KeysForm.svelte index f193629a7..cb262f1e8 100644 --- a/app/src/lib/components/KeysForm.svelte +++ b/app/src/lib/components/KeysForm.svelte @@ -9,9 +9,9 @@ import Button from '$lib/components/Button.svelte'; import Link from '$lib/components/Link.svelte'; import Section from '$lib/components/settings/Section.svelte'; + import { showError } from '$lib/notifications/toasts'; import { copyToClipboard } from '$lib/utils/clipboard'; import { getContext, getContextStore } from '$lib/utils/context'; - import * as toasts from '$lib/utils/toasts'; import { openExternalUrl } from '$lib/utils/url'; import { BaseBranch } from '$lib/vbranches/types'; import { onMount } from 'svelte'; @@ -51,7 +51,7 @@ try { projectService.updateProject({ ...project, ...detail }); } catch (err: any) { - toasts.error(err.message); + showError('Failed to update key', err); } } diff --git a/app/src/lib/components/Login.svelte b/app/src/lib/components/Login.svelte index db4ffe0fc..59d3b1465 100644 --- a/app/src/lib/components/Login.svelte +++ b/app/src/lib/components/Login.svelte @@ -1,8 +1,8 @@ {#if prompt} diff --git a/app/src/lib/components/ProblemLoadingRepo.svelte b/app/src/lib/components/ProblemLoadingRepo.svelte index 9d80357e2..f20a1134f 100644 --- a/app/src/lib/components/ProblemLoadingRepo.svelte +++ b/app/src/lib/components/ProblemLoadingRepo.svelte @@ -5,6 +5,7 @@ import loadErrorSvg from '$lib/assets/illustrations/load-error.svg?raw'; import { ProjectService, Project } from '$lib/backend/projects'; import Icon from '$lib/components/Icon.svelte'; + import { showError } from '$lib/notifications/toasts'; import { getContext } from '$lib/utils/context'; import * as toasts from '$lib/utils/toasts'; import { goto } from '$app/navigation'; @@ -24,9 +25,9 @@ await projectService.deleteProject(project.id); toasts.success('Project deleted'); goto('/'); - } catch (e) { - console.error(e); - toasts.error('Failed to delete project'); + } catch (err: any) { + console.error(err); + showError('Failed to delete project', err); } finally { loading = false; projectService.reload(); diff --git a/app/src/lib/components/UpdateBaseButton.svelte b/app/src/lib/components/UpdateBaseButton.svelte index 91fb912b8..e50e5db32 100644 --- a/app/src/lib/components/UpdateBaseButton.svelte +++ b/app/src/lib/components/UpdateBaseButton.svelte @@ -1,7 +1,7 @@