authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-06-20 10:54:56-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-06-20 10:54:56-07:00
loge55dd0067dde55770a4f7f7d1720615fcfd56389
tree5b744fc89b0073169cc561b9616b1fa61ec054e4
parent8c3755aeccd5fc90fe66f6ca4d776c0e370fe46e
signature Signed by PGP key B5690EEEBB952194

[codex] Structure preview session key errors (#3388)

Co-authored-by: codex <codex@users.noreply.github.com>

1 files changed, 12 insertions(+), 2 deletions(-)

apps/web/src/components/preview/usePreviewSession.ts+12-2
...@@ -4,6 +4,7 @@ import { useAtomValue } from "@effect/atom-react";...@@ -4,6 +4,7 @@ import { useAtomValue } from "@effect/atom-react";
4import { parseScopedThreadKey, scopedThreadKey } from "@t3tools/client-runtime/environment";4import { parseScopedThreadKey, scopedThreadKey } from "@t3tools/client-runtime/environment";
5import { runAtomCommand } from "@t3tools/client-runtime/state/runtime";5import { runAtomCommand } from "@t3tools/client-runtime/state/runtime";
6import type { ScopedThreadRef } from "@t3tools/contracts";6import type { ScopedThreadRef } from "@t3tools/contracts";
7import * as Schema from "effect/Schema";
7import { AsyncResult, Atom } from "effect/unstable/reactivity";8import { AsyncResult, Atom } from "effect/unstable/reactivity";
89
9import {10import {
...@@ -13,10 +14,19 @@ import {...@@ -13,10 +14,19 @@ import {
13} from "~/previewStateStore";14} from "~/previewStateStore";
14import { previewEnvironment } from "~/state/preview";15import { previewEnvironment } from "~/state/preview";
1516
17class PreviewSessionThreadKeyParseError extends Schema.TaggedErrorClass<PreviewSessionThreadKeyParseError>()(
18 "PreviewSessionThreadKeyParseError",
19 { threadKey: Schema.String },
20) {
21 override get message(): string {
22 return `Invalid scoped preview thread key: ${this.threadKey}`;
23 }
24}
25
16const previewSessionSyncAtom = Atom.family((threadKey: string) => {26const previewSessionSyncAtom = Atom.family((threadKey: string) => {
17 const threadRef = parseScopedThreadKey(threadKey);27 const threadRef = parseScopedThreadKey(threadKey);
18 if (!threadRef) {28 if (threadRef === null) {
19 throw new Error(`Invalid scoped preview thread key: ${threadKey}`);29 throw new PreviewSessionThreadKeyParseError({ threadKey });
20 }30 }
2131
22 const sessionsAtom = previewEnvironment.list({32 const sessionsAtom = previewEnvironment.list({