From 6240442f65cbb0ec5f581487a748d4604e4674b5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 10 May 2026 16:13:14 +0000 Subject: [PATCH] Add structured environment label errors Co-authored-by: Julius Marminge --- .../Layers/ServerEnvironmentLabel.test.ts | 15 +++++++++-- .../Layers/ServerEnvironmentLabel.ts | 25 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/apps/server/src/environment/Layers/ServerEnvironmentLabel.test.ts b/apps/server/src/environment/Layers/ServerEnvironmentLabel.test.ts index 0342e51664..298f42eb50 100644 --- a/apps/server/src/environment/Layers/ServerEnvironmentLabel.test.ts +++ b/apps/server/src/environment/Layers/ServerEnvironmentLabel.test.ts @@ -4,6 +4,7 @@ import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; import { + ServerEnvironmentLabelCommandError, ServerEnvironmentLabelCommandRunner, resolveServerEnvironmentLabel, } from "./ServerEnvironmentLabel.ts"; @@ -20,7 +21,10 @@ function commandRunnerLayer(input: { readonly run: ( command: string, args: readonly string[], - ) => Effect.Effect<{ readonly stdout: string; readonly exitCode: number }, unknown>; + ) => Effect.Effect< + { readonly stdout: string; readonly exitCode: number }, + ServerEnvironmentLabelCommandError + >; }) { return Layer.mock(ServerEnvironmentLabelCommandRunner)({ run: (command, args) => @@ -143,7 +147,14 @@ describe("resolveServerEnvironmentLabel", () => { Effect.provide( testLayer( commandRunnerLayer({ - run: () => Effect.fail(new Error("spawn scutil ENOENT")), + run: (command, args) => + Effect.fail( + new ServerEnvironmentLabelCommandError({ + command, + args: [...args], + message: "spawn scutil ENOENT", + }), + ), }), ), ), diff --git a/apps/server/src/environment/Layers/ServerEnvironmentLabel.ts b/apps/server/src/environment/Layers/ServerEnvironmentLabel.ts index fc1f21c8ca..4e0076a7b1 100644 --- a/apps/server/src/environment/Layers/ServerEnvironmentLabel.ts +++ b/apps/server/src/environment/Layers/ServerEnvironmentLabel.ts @@ -5,6 +5,7 @@ import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; +import * as Schema from "effect/Schema"; import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"; import { collectUint8StreamText } from "../../stream/collectUint8StreamText.ts"; @@ -24,9 +25,19 @@ interface ServerEnvironmentLabelCommandRunnerShape { readonly run: ( command: string, args: readonly string[], - ) => Effect.Effect; + ) => Effect.Effect; } +export class ServerEnvironmentLabelCommandError extends Schema.TaggedErrorClass()( + "ServerEnvironmentLabelCommandError", + { + command: Schema.String, + args: Schema.Array(Schema.String), + message: Schema.String, + cause: Schema.optional(Schema.Defect), + }, +) {} + export class ServerEnvironmentLabelCommandRunner extends Context.Service< ServerEnvironmentLabelCommandRunner, ServerEnvironmentLabelCommandRunnerShape @@ -59,7 +70,17 @@ export const ServerEnvironmentLabelCommandRunnerLive = Layer.effect( stdout: stdout.text, exitCode: Number(exitCode), }; - }), + }).pipe( + Effect.mapError( + (cause) => + new ServerEnvironmentLabelCommandError({ + command, + args: [...args], + message: `Failed to run friendly host label command: ${command}.`, + cause, + }), + ), + ), ), }); }),