[codex] Structure thread archive blocked error (#3451)
This commit is contained in:
1 parent
2a29de7502
commit
0debebafbb
2 files changed
+34
-6
No files matched your search
@@ -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.");
|
||||
});
|
||||
});
|
||||
@@ -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>()(
|
||||
"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,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user