Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions scripts/mobile-native-static-check.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { assert, it } from "@effect/vitest";

import { NativeStaticCheckCommandError } from "./mobile-native-static-check.ts";

it("describes failed native static-analysis commands structurally", () => {
const error = new NativeStaticCheckCommandError({
command: "swiftlint",
args: ["lint", "--strict"],
cwd: "/repo/apps/mobile",
exitCode: 2,
});

assert.equal(error.command, "swiftlint");
assert.deepStrictEqual(error.args, ["lint", "--strict"]);
assert.equal(error.cwd, "/repo/apps/mobile");
assert.equal(error.exitCode, 2);
assert.equal(error.message, "Native static check command 'swiftlint' exited with code 2.");
});
25 changes: 19 additions & 6 deletions scripts/mobile-native-static-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { isCommandAvailable, resolveSpawnCommand } from "@t3tools/shared/shell";
import * as Console from "effect/Console";
import * as Data from "effect/Data";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Logger from "effect/Logger";
import * as Path from "effect/Path";
import * as PlatformError from "effect/PlatformError";
import * as Schema from "effect/Schema";
import { Command } from "effect/unstable/cli";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";

Expand All @@ -18,9 +18,19 @@ interface NativeStaticTool {
readonly installHint: string;
}

class NativeStaticCheckError extends Data.TaggedError("NativeStaticCheckError")<{
readonly message: string;
}> {}
export class NativeStaticCheckCommandError extends Schema.TaggedErrorClass<NativeStaticCheckCommandError>()(
"NativeStaticCheckCommandError",
{
command: Schema.String,
args: Schema.Array(Schema.String),
cwd: Schema.String,
exitCode: Schema.Int,
},
) {
override get message(): string {
return `Native static check command '${this.command}' exited with code ${this.exitCode}.`;
}
}

const tools = [
{
Expand Down Expand Up @@ -85,8 +95,11 @@ const runCommand = Effect.fn("runCommand")(function* (
const exitCode = Number(yield* child.exitCode);

if (exitCode !== 0) {
return yield* new NativeStaticCheckError({
message: `Command exited with non-zero exit code (${exitCode})`,
return yield* new NativeStaticCheckCommandError({
command,
args,
cwd,
exitCode,
});
}
});
Expand Down
Loading