Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
[codex] Structure server CLI failures (#3450)
Julius Marminge68c0dd3b7095
diff --git a/apps/server/scripts/cli.ts b/apps/server/scripts/cli.tsindex a158eaa06..00b6c4cfc 100644--- a/apps/server/scripts/cli.ts+++ b/apps/server/scripts/cli.ts@@ -1,7 +1,6 @@#!/usr/bin/env nodeimport * as NodeRuntime from "@effect/platform-node/NodeRuntime";import * as NodeServices from "@effect/platform-node/NodeServices";-import * as Data from "effect/Data";import * as Effect from "effect/Effect";import * as FileSystem from "effect/FileSystem";import * as Logger from "effect/Logger";@@ -20,6 +19,14 @@ import { fromJsonStringPretty } from "@t3tools/shared/schemaJson";import { fromYaml } from "@t3tools/shared/schemaYaml";import { resolveSpawnCommand } from "@t3tools/shared/shell";import serverPackageJson from "../package.json" with { type: "json" };+import {+ ServerCliBuildAssetMissingError,+ ServerCliCommandExitError,+ ServerCliDevelopmentIconSourceMissingError,+ ServerCliDevelopmentIconTargetMissingError,+ ServerCliPublishIconSourceMissingError,+ ServerCliPublishIconTargetMissingError,+} from "./cliErrors.ts";interface PackageJson {name: string;@@ -47,11 +54,6 @@ const WorkspaceConfig = Schema.Struct({type WorkspaceConfig = typeof WorkspaceConfig.Type;const decodeWorkspaceConfig = Schema.decodeEffect(fromYaml(WorkspaceConfig));-class CliError extends Data.TaggedError("CliError")<{- readonly message: string;- readonly cause?: unknown;-}> {}-const RepoRoot = Effect.service(Path.Path).pipe(Effect.flatMap((path) => path.fromFileUrl(new URL("../../..", import.meta.url))),);@@ -64,14 +66,17 @@ const readWorkspaceConfig = Effect.fn("readWorkspaceConfig")(function* () {return yield* decodeWorkspaceConfig(workspaceYaml);});-const runCommand = Effect.fn("runCommand")(function* (command: ChildProcess.Command) {+const runCommand = Effect.fn("runCommand")(function* (command: ChildProcess.StandardCommand) {const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;const child = yield* spawner.spawn(command);const exitCode = yield* child.exitCode;if (exitCode !== 0) {- return yield* new CliError({- message: `Command exited with non-zero exit code (${exitCode})`,+ return yield* new ServerCliCommandExitError({+ command: command.command,+ args: command.args,+ cwd: command.options.cwd,+ exitCode,});}});@@ -95,14 +100,10 @@ const applyPublishIconOverrides = Effect.fn("applyPublishIconOverrides")(functioconst backupPath = `${targetPath}.publish-bak`;if (!(yield* fs.exists(sourcePath))) {- return yield* new CliError({- message: `Missing publish icon source: ${sourcePath}`,- });+ return yield* new ServerCliPublishIconSourceMissingError({ sourcePath });}if (!(yield* fs.exists(targetPath))) {- return yield* new CliError({- message: `Missing publish icon target: ${targetPath}. Run the build subcommand first.`,- });+ return yield* new ServerCliPublishIconTargetMissingError({ targetPath });}yield* fs.copyFile(targetPath, backupPath);@@ -138,14 +139,10 @@ const applyDevelopmentIconOverrides = Effect.fn("applyDevelopmentIconOverrides")const targetPath = path.join(serverDir, override.targetRelativePath);if (!(yield* fs.exists(sourcePath))) {- return yield* new CliError({- message: `Missing development icon source: ${sourcePath}`,- });+ return yield* new ServerCliDevelopmentIconSourceMissingError({ sourcePath });}if (!(yield* fs.exists(targetPath))) {- return yield* new CliError({- message: `Missing development icon target: ${targetPath}. Build web first.`,- });+ return yield* new ServerCliDevelopmentIconTargetMissingError({ targetPath });}yield* fs.copyFile(sourcePath, targetPath);@@ -245,9 +242,7 @@ const publishCmd = Command.make(for (const relPath of ["dist/bin.mjs", "dist/client/index.html"]) {const abs = path.join(serverDir, relPath);if (!(yield* fs.exists(abs))) {- return yield* new CliError({- message: `Missing build asset: ${abs}. Run the build subcommand first.`,- });+ return yield* new ServerCliBuildAssetMissingError({ assetPath: abs });}}diff --git a/apps/server/scripts/cliErrors.test.ts b/apps/server/scripts/cliErrors.test.tsnew file mode 100644index 000000000..91754290d--- /dev/null+++ b/apps/server/scripts/cliErrors.test.ts@@ -0,0 +1,31 @@+import { assert, describe, it } from "@effect/vitest";++import { ServerCliBuildAssetMissingError, ServerCliCommandExitError } from "./cliErrors.ts";++describe("server CLI errors", () => {+ it("preserves failed command context without changing its message", () => {+ const error = new ServerCliCommandExitError({+ command: "vp",+ args: ["pm", "publish"],+ cwd: "/repo",+ exitCode: 17,+ });++ assert.equal(error._tag, "ServerCliCommandExitError");+ assert.equal(error.command, "vp");+ assert.deepEqual(error.args, ["pm", "publish"]);+ assert.equal(error.cwd, "/repo");+ assert.equal(error.exitCode, 17);+ assert.equal(error.message, "Command exited with non-zero exit code (17)");+ });++ it("preserves a representative missing asset path", () => {+ const error = new ServerCliBuildAssetMissingError({ assetPath: "/repo/server.mjs" });++ assert.equal(error.assetPath, "/repo/server.mjs");+ assert.equal(+ error.message,+ "Missing build asset: /repo/server.mjs. Run the build subcommand first.",+ );+ });+});diff --git a/apps/server/scripts/cliErrors.ts b/apps/server/scripts/cliErrors.tsnew file mode 100644index 000000000..d384c745f--- /dev/null+++ b/apps/server/scripts/cliErrors.ts@@ -0,0 +1,70 @@+import * as Schema from "effect/Schema";++export class ServerCliCommandExitError extends Schema.TaggedErrorClass<ServerCliCommandExitError>()(+ "ServerCliCommandExitError",+ {+ command: Schema.String,+ args: Schema.Array(Schema.String),+ cwd: Schema.optional(Schema.String),+ exitCode: Schema.Int,+ },+) {+ override get message(): string {+ return `Command exited with non-zero exit code (${this.exitCode})`;+ }+}++export class ServerCliPublishIconSourceMissingError extends Schema.TaggedErrorClass<ServerCliPublishIconSourceMissingError>()(+ "ServerCliPublishIconSourceMissingError",+ {+ sourcePath: Schema.String,+ },+) {+ override get message(): string {+ return `Missing publish icon source: ${this.sourcePath}`;+ }+}++export class ServerCliPublishIconTargetMissingError extends Schema.TaggedErrorClass<ServerCliPublishIconTargetMissingError>()(+ "ServerCliPublishIconTargetMissingError",+ {+ targetPath: Schema.String,+ },+) {+ override get message(): string {+ return `Missing publish icon target: ${this.targetPath}. Run the build subcommand first.`;+ }+}++export class ServerCliDevelopmentIconSourceMissingError extends Schema.TaggedErrorClass<ServerCliDevelopmentIconSourceMissingError>()(+ "ServerCliDevelopmentIconSourceMissingError",+ {+ sourcePath: Schema.String,+ },+) {+ override get message(): string {+ return `Missing development icon source: ${this.sourcePath}`;+ }+}++export class ServerCliDevelopmentIconTargetMissingError extends Schema.TaggedErrorClass<ServerCliDevelopmentIconTargetMissingError>()(+ "ServerCliDevelopmentIconTargetMissingError",+ {+ targetPath: Schema.String,+ },+) {+ override get message(): string {+ return `Missing development icon target: ${this.targetPath}. Build web first.`;+ }+}++export class ServerCliBuildAssetMissingError extends Schema.TaggedErrorClass<ServerCliBuildAssetMissingError>()(+ "ServerCliBuildAssetMissingError",+ {+ assetPath: Schema.String,+ },+) {+ override get message(): string {+ return `Missing build asset: ${this.assetPath}. Run the build subcommand first.`;+ }+}