The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 22:45 UTC
[codex] Preserve desktop asset probe failures (#3373)
Co-authored-by: codex <codex@users.noreply.github.com>
Julius Marminge committed
Jun 20, 2026 at 11:10 UTC
61aade9ea4e7df15fd196d9805a00d24ed715f7c
2 files changed
+94
-8
apps/desktop/src/app/DesktopAssets.test.ts
new
+57
@@ -0,0 +1,57 @@
1
+import * as NodeServices from "@effect/platform-node/NodeServices";
2
+import { assert, describe, it } from "@effect/vitest";
3
+import * as Effect from "effect/Effect";
4
+import * as FileSystem from "effect/FileSystem";
5
+import * as Layer from "effect/Layer";
6
+import * as PlatformError from "effect/PlatformError";
7
+
8
+import * as DesktopAssets from "./DesktopAssets.ts";
9
+import * as DesktopConfig from "./DesktopConfig.ts";
10
+import * as DesktopEnvironment from "./DesktopEnvironment.ts";
11
+
12
+const environmentLayer = DesktopEnvironment.layer({
13
+ dirname: "/repo/apps/desktop/dist-electron",
14
+ homeDirectory: "/Users/alice",
15
+ platform: "darwin",
16
+ processArch: "arm64",
17
+ appVersion: "1.2.3",
18
+ appPath: "/Applications/T3 Code.app/Contents/Resources/app.asar",
19
+ isPackaged: true,
20
+ resourcesPath: "/Applications/T3 Code.app/Contents/Resources",
21
+ runningUnderArm64Translation: false,
22
+}).pipe(Layer.provide(Layer.mergeAll(NodeServices.layer, DesktopConfig.layerTest({}))));
23
+
24
+describe("DesktopAssets", () => {
25
+ it.effect("preserves the failed asset candidate and filesystem cause", () =>
26
+ Effect.gen(function* () {
27
+ const fileName = "custom.bin";
28
+ const candidatePath = "/repo/apps/desktop/resources/custom.bin";
29
+ const cause = PlatformError.systemError({
30
+ _tag: "PermissionDenied",
31
+ module: "FileSystem",
32
+ method: "exists",
33
+ pathOrDescriptor: candidatePath,
34
+ description: "private filesystem diagnostic",
35
+ });
36
+ const fileSystemLayer = FileSystem.layerNoop({
37
+ exists: (path) => (path === candidatePath ? Effect.fail(cause) : Effect.succeed(false)),
38
+ });
39
+ const assetsLayer = DesktopAssets.layer.pipe(
40
+ Layer.provide(Layer.merge(fileSystemLayer, environmentLayer)),
41
+ );
42
+ const assets = yield* DesktopAssets.DesktopAssets.pipe(Effect.provide(assetsLayer));
43
+
44
+ const error = yield* assets.resolveResourcePath(fileName).pipe(Effect.flip);
45
+
46
+ assert.instanceOf(error, DesktopAssets.DesktopAssetProbeError);
47
+ assert.equal(error.fileName, fileName);
48
+ assert.equal(error.candidatePath, candidatePath);
49
+ assert.strictEqual(error.cause, cause);
50
+ assert.equal(
51
+ error.message,
52
+ `Failed to probe desktop asset "${fileName}" at ${candidatePath}.`,
53
+ );
54
+ assert.notInclude(error.message, "private filesystem diagnostic");
55
+ }),
56
+ );
57
+});
apps/desktop/src/app/DesktopAssets.ts
+37
-8
@@ -3,6 +3,7 @@ import * as Effect from "effect/Effect";
3
import * as FileSystem from "effect/FileSystem";
4
import * as Layer from "effect/Layer";
5
import * as Option from "effect/Option";
6
+import * as Schema from "effect/Schema";
7
8
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
9
@@ -12,11 +13,26 @@ export interface DesktopIconPaths {
13
readonly png: Option.Option<string>;
14
}
15
16
+export class DesktopAssetProbeError extends Schema.TaggedErrorClass<DesktopAssetProbeError>()(
17
+ "DesktopAssetProbeError",
18
+ {
19
+ fileName: Schema.String,
20
+ candidatePath: Schema.String,
21
+ cause: Schema.Defect(),
22
+ },
23
+) {
24
+ override get message(): string {
25
+ return `Failed to probe desktop asset "${this.fileName}" at ${this.candidatePath}.`;
26
+ }
27
+}
28
+
29
export class DesktopAssets extends Context.Service<
30
DesktopAssets,
31
{
32
readonly iconPaths: Effect.Effect<DesktopIconPaths>;
19
- readonly resolveResourcePath: (fileName: string) => Effect.Effect<Option.Option<string>>;
33
+ readonly resolveResourcePath: (
34
+ fileName: string,
35
+ ) => Effect.Effect<Option.Option<string>, DesktopAssetProbeError>;
36
}
37
>()("@t3tools/desktop/app/DesktopAssets") {}
38
@@ -24,14 +40,20 @@ const resolveResourcePath = Effect.fn("desktop.assets.resolveResourcePath")(func
40
fileName: string,
41
): Effect.fn.Return<
42
Option.Option<string>,
27
- never,
43
+ DesktopAssetProbeError,
44
FileSystem.FileSystem | DesktopEnvironment.DesktopEnvironment
45
> {
46
const fileSystem = yield* FileSystem.FileSystem;
47
const environment = yield* DesktopEnvironment.DesktopEnvironment;
48
const candidates = environment.resolveResourcePathCandidates(fileName);
49
for (const candidate of candidates) {
34
- const exists = yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false));
50
+ const exists = yield* fileSystem
51
+ .exists(candidate)
52
+ .pipe(
53
+ Effect.mapError(
54
+ (cause) => new DesktopAssetProbeError({ fileName, candidatePath: candidate, cause }),
55
+ ),
56
+ );
57
if (exists) {
58
return Option.some(candidate);
59
}
@@ -43,16 +65,23 @@ const resolveIconPath = Effect.fn("desktop.assets.resolveIconPath")(function* (
65
ext: keyof DesktopIconPaths,
66
): Effect.fn.Return<
67
Option.Option<string>,
46
- never,
68
+ DesktopAssetProbeError,
69
FileSystem.FileSystem | DesktopEnvironment.DesktopEnvironment
70
> {
71
const fileSystem = yield* FileSystem.FileSystem;
72
const environment = yield* DesktopEnvironment.DesktopEnvironment;
73
if (environment.isDevelopment && environment.platform === "darwin" && ext === "png") {
74
const developmentDockIconPath = environment.developmentDockIconPath;
53
- const developmentDockIconExists = yield* fileSystem
54
- .exists(developmentDockIconPath)
55
- .pipe(Effect.orElseSucceed(() => false));
75
+ const developmentDockIconExists = yield* fileSystem.exists(developmentDockIconPath).pipe(
76
+ Effect.mapError(
77
+ (cause) =>
78
+ new DesktopAssetProbeError({
79
+ fileName: "icon.png",
80
+ candidatePath: developmentDockIconPath,
81
+ cause,
82
+ }),
83
+ ),
84
+ );
85
if (developmentDockIconExists) {
86
return Option.some(developmentDockIconPath);
87
}
@@ -61,7 +90,7 @@ const resolveIconPath = Effect.fn("desktop.assets.resolveIconPath")(function* (
90
return yield* resolveResourcePath(`icon.${ext}`);
91
});
92
64
-const make = Effect.gen(function* () {
93
+export const make = Effect.gen(function* () {
94
const context = yield* Effect.context<
95
FileSystem.FileSystem | DesktopEnvironment.DesktopEnvironment
96
>();