Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(cowork): distinguish workspace action failures
thinhlpga0358ac8097b
diff --git a/web-app/src/containers/CoworkWorkspacePill.tsx b/web-app/src/containers/CoworkWorkspacePill.tsxindex f89cfca67..515e3a1a0 100644--- a/web-app/src/containers/CoworkWorkspacePill.tsx+++ b/web-app/src/containers/CoworkWorkspacePill.tsx@@ -42,8 +42,24 @@ export function CoworkWorkspacePill({const serviceHub = useServiceHub()const folderName = folder ? basenameOf(folder) : null- const notifyMissingWorkspace = () => {- toast.error(t('common:workspace.missing'), {+ const notifyWorkspaceActionError = (+ action: 'open' | 'reveal',+ error: unknown+ ) => {+ const detail = error instanceof Error ? error.message : String(error)+ const missing = /ENOENT|no such file|does not exist|not found|path not found/i.test(detail)+ const title = missing+ ? t('common:workspace.unavailable')+ : t(+ action === 'open'+ ? 'common:workspace.openFailed'+ : 'common:workspace.revealFailed'+ )++ toast.error(title, {+ description: missing+ ? t('common:workspace.missing', { folder: folderName })+ : detail,action: {label: t('common:workspace.change'),onClick: onAttach,@@ -55,8 +71,8 @@ export function CoworkWorkspacePill({if (!folder) returntry {await serviceHub.opener().openPath(folder)- } catch {- notifyMissingWorkspace()+ } catch (error) {+ notifyWorkspaceActionError('open', error)}}@@ -64,8 +80,8 @@ export function CoworkWorkspacePill({if (!folder) returntry {await serviceHub.opener().revealItemInDir(folder)- } catch {- notifyMissingWorkspace()+ } catch (error) {+ notifyWorkspaceActionError('reveal', error)}}diff --git a/web-app/src/containers/__tests__/CoworkWorkspacePill.test.tsx b/web-app/src/containers/__tests__/CoworkWorkspacePill.test.tsxindex e7c38ea5a..706061545 100644--- a/web-app/src/containers/__tests__/CoworkWorkspacePill.test.tsx+++ b/web-app/src/containers/__tests__/CoworkWorkspacePill.test.tsx@@ -99,8 +99,9 @@ describe('CoworkWorkspacePill', () => {await vi.waitFor(() => {expect(toastError).toHaveBeenCalledWith(- 'common:workspace.missing',+ 'common:workspace.unavailable',expect.objectContaining({+ description: 'common:workspace.missing jan-app',action: expect.objectContaining({label: 'common:workspace.change',onClick: onAttach,@@ -108,6 +109,9 @@ describe('CoworkWorkspacePill', () => {}))})+ const [, options] = toastError.mock.calls[0]+ options.action.onClick()+ expect(onAttach).toHaveBeenCalledOnce()})it('notifies and offers a replacement when the folder cannot be revealed', async () => {@@ -125,8 +129,9 @@ describe('CoworkWorkspacePill', () => {await vi.waitFor(() => {expect(toastError).toHaveBeenCalledWith(- 'common:workspace.missing',+ 'common:workspace.unavailable',expect.objectContaining({+ description: 'common:workspace.missing jan-app',action: expect.objectContaining({label: 'common:workspace.change',onClick: onAttach,diff --git a/web-app/src/locales/en/common.json b/web-app/src/locales/en/common.jsonindex b36636bb5..33b6cdb65 100644--- a/web-app/src/locales/en/common.json+++ b/web-app/src/locales/en/common.json@@ -690,7 +690,10 @@"detach": "Detach folder","open": "Open","reveal": "Reveal",- "missing": "This folder isn't there anymore. Attach a different one.",+ "unavailable": "Workspace unavailable",+ "missing": "The workspace folder {{folder}} is no longer available. Choose a different folder.",+ "openFailed": "Couldn't open workspace",+ "revealFailed": "Couldn't reveal workspace","a11yWithFolder": "Project folder {{folder}}, attached with read and write access. Change or detach it.","a11yNoFolder": "No project folder attached. Attach one."},