From 7780446fc31d9148e6b127db95c0d79d2a4668cd Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 20 Jun 2026 17:28:49 -0700 Subject: [PATCH] Structure thread archive blocked error Co-authored-by: codex --- apps/web/src/hooks/useThreadActions.test.ts | 19 +++++++++++++++++++ apps/web/src/hooks/useThreadActions.ts | 21 +++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 apps/web/src/hooks/useThreadActions.test.ts diff --git a/apps/web/src/hooks/useThreadActions.test.ts b/apps/web/src/hooks/useThreadActions.test.ts new file mode 100644 index 00000000000..c5385211591 --- /dev/null +++ b/apps/web/src/hooks/useThreadActions.test.ts @@ -0,0 +1,19 @@ +import { EnvironmentId, ThreadId } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { ThreadArchiveBlockedError } from "./useThreadActions"; + +describe("ThreadArchiveBlockedError", () => { + it("keeps the blocked thread context with the fixed message", () => { + const error = new ThreadArchiveBlockedError({ + environmentId: EnvironmentId.make("environment-1"), + threadId: ThreadId.make("thread-1"), + }); + + expect(error).toMatchObject({ + environmentId: "environment-1", + threadId: "thread-1", + }); + expect(error.message).toBe("Cannot archive a running thread."); + }); +}); diff --git a/apps/web/src/hooks/useThreadActions.ts b/apps/web/src/hooks/useThreadActions.ts index 35783348068..07655ad30d7 100644 --- a/apps/web/src/hooks/useThreadActions.ts +++ b/apps/web/src/hooks/useThreadActions.ts @@ -4,9 +4,9 @@ import { scopeThreadRef, } from "@t3tools/client-runtime/environment"; import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; -import { type ScopedThreadRef, ThreadId } from "@t3tools/contracts"; +import { EnvironmentId, type ScopedThreadRef, ThreadId } from "@t3tools/contracts"; import * as Cause from "effect/Cause"; -import * as Data from "effect/Data"; +import * as Schema from "effect/Schema"; import { AsyncResult } from "effect/unstable/reactivity"; import { useRouter } from "@tanstack/react-router"; import { useCallback, useMemo, useRef } from "react"; @@ -27,9 +27,17 @@ import { stackedThreadToast, toastManager } from "../components/ui/toast"; import { useClientSettings } from "./useSettings"; import { useAtomCommand } from "../state/use-atom-command"; -export class ThreadArchiveBlockedError extends Data.TaggedError("ThreadArchiveBlockedError")<{ - readonly message: string; -}> {} +export class ThreadArchiveBlockedError extends Schema.TaggedErrorClass()( + "ThreadArchiveBlockedError", + { + environmentId: EnvironmentId, + threadId: ThreadId, + }, +) { + override get message(): string { + return "Cannot archive a running thread."; + } +} export function useThreadActions() { const closeTerminal = useAtomCommand(terminalEnvironment.close); @@ -89,7 +97,8 @@ export function useThreadActions() { return AsyncResult.failure( Cause.fail( new ThreadArchiveBlockedError({ - message: "Cannot archive a running thread.", + environmentId: threadRef.environmentId, + threadId: threadRef.threadId, }), ), );