Skip to content
Open
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
4 changes: 2 additions & 2 deletions packages/core/src/artifacts/artifacts-lock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { open, readFile, rename, unlink } from "node:fs/promises";
import path from "node:path";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";

const LOCK_RETRY_DELAY_MS = 50;
const LOCK_TIMEOUT_MS = 15_000;
Expand Down Expand Up @@ -113,7 +113,7 @@ async function acquireLock(lockPath: string, deadline: number): Promise<void> {
return;
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "EEXIST") {
throw error;
throw toCaatingaError(error);
}

owner = await readLockOwner(lockPath);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/artifacts/read-artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile } from "node:fs/promises";
import path from "node:path";
import { z } from "zod";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import {
CaatingaArtifactsSchema,
CURRENT_ARTIFACTS_SCHEMA_VERSION,
Expand Down Expand Up @@ -44,6 +44,6 @@ export async function readArtifacts(cwd = process.cwd()): Promise<CaatingaArtifa
);
}

throw error;
throw toCaatingaError(error);
}
}
3 changes: 2 additions & 1 deletion packages/core/src/artifacts/write-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomBytes } from "node:crypto";
import { mkdir, rename, unlink, writeFile } from "node:fs/promises";
import path from "node:path";
import type { CaatingaArtifacts } from "./artifact.schema.js";
import { toCaatingaError } from "../errors/CaatingaError.js";

export async function writeArtifacts(
artifacts: CaatingaArtifacts,
Expand All @@ -18,7 +19,7 @@ export async function writeArtifacts(
await rename(tmpPath, artifactsPath);
} catch (error) {
await unlink(tmpPath).catch(() => undefined);
throw error;
throw toCaatingaError(error);
}

return artifactsPath;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/config/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { access } from "node:fs/promises";
import path from "node:path";
import { createJiti } from "jiti";
import { z } from "zod";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { isDependenciesNotInstalledError } from "./is-dependencies-not-installed-error.js";
import { CaatingaConfigSchema, type CaatingaConfig } from "./config.schema.js";

Expand Down Expand Up @@ -47,6 +47,6 @@ export async function loadConfig(options: LoadConfigOptions = {}): Promise<Caati
);
}

throw error;
throw toCaatingaError(error);
}
}
4 changes: 2 additions & 2 deletions packages/core/src/contracts/build-contract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CaatingaConfig } from "../config/config.schema.js";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { checkBinary } from "../shell/check-binary.js";
import { runCommand } from "../shell/run-command.js";
import { resolveContract } from "./resolve-contract.js";
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function buildContract(options: BuildContractOptions) {
error
);
}
throw error;
throw toCaatingaError(error);
}

const wasmPath = await resolveWasmArtifactPath(contract.wasmPath, {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/contracts/build-workspace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "node:path";
import type { CaatingaConfig } from "../config/config.schema.js";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { checkBinary } from "../shell/check-binary.js";
import { runCommand } from "../shell/run-command.js";
import { resolveContract } from "./resolve-contract.js";
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function buildWorkspace(options: BuildWorkspaceOptions) {
error
);
}
throw error;
throw toCaatingaError(error);
}

const contracts = await Promise.all(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/contracts/estimate-deploy-cost.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import { readArtifacts } from "../artifacts/read-artifacts.js";
import type { CaatingaConfig } from "../config/config.schema.js";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { resolveNetwork } from "../networks/resolve-network.js";
import { checkBinary } from "../shell/check-binary.js";
import { runCommand } from "../shell/run-command.js";
Expand Down Expand Up @@ -106,7 +106,7 @@ export async function estimateDeployCost(
error
);
}
throw error;
throw toCaatingaError(error);
}

const simulateArgs = ["tx", "simulate", "--source-account", source, buildOutput];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/contracts/invoke-contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readArtifacts } from "../artifacts/read-artifacts.js";
import type { CaatingaConfig } from "../config/config.schema.js";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { resolveNetwork } from "../networks/resolve-network.js";
import { checkBinary } from "../shell/check-binary.js";
import { runCommand } from "../shell/run-command.js";
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function invokeContract(options: InvokeContractOptions) {
);
}

throw error;
throw toCaatingaError(error);
}

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/contracts/resolve-method-args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { formatNamedCliArgs } from "./format-cli-args.js";
import { resolveSourceAddress } from "./resolve-source-address.js";
import type { DeployArgValue } from "./resolve-deploy-args.js";
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function resolveMethodArgs(
error
);
}
throw error;
throw toCaatingaError(error);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/contracts/resolve-source-address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { checkBinary } from "../shell/check-binary.js";
import { runCommand } from "../shell/run-command.js";
import { assertSafeSourceAccount } from "./source-account.js";
Expand Down Expand Up @@ -29,7 +29,7 @@ export async function resolveSourceAddress(options: {
error
);
}
throw error;
throw toCaatingaError(error);
}

const address = (result.stdout || result.all || "").trim();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/contracts/verify-dependency-contract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CaatingaArtifacts } from "../artifacts/artifact.schema.js";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import type { ResolvedNetwork } from "../networks/resolve-network.js";
import { runCommand } from "../shell/run-command.js";
import { buildStellarNetworkArgs } from "../stellar-cli/build-stellar-network-args.js";
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function verifyDependencyContract(options: {
);
}

throw error;
throw toCaatingaError(error);
}
}

Expand Down
42 changes: 42 additions & 0 deletions packages/core/src/errors/to-caatinga-error-wrapping.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { mkdir, mkdtemp, rm } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { CaatingaError, CaatingaErrorCode } from "./CaatingaError.js";
import { readArtifacts } from "../artifacts/read-artifacts.js";
import { createInitialArtifacts, writeArtifacts } from "../artifacts/write-artifacts.js";

// #88: raw NodeJS.ErrnoException errors used to escape core catch blocks
// untyped. These exercise the converted sites with a real (non-ENOENT,
// non-SyntaxError) fs failure and assert they now surface as CaatingaError.
describe("core catch blocks wrap raw errors as CaatingaError (#88)", () => {
let tmpDir: string;

afterEach(async () => {
if (tmpDir) {
await rm(tmpDir, { recursive: true, force: true });
}
});

it("writeArtifacts wraps a raw rename failure", async () => {
tmpDir = await mkdtemp(path.join(os.tmpdir(), "caatinga-wrap-"));
// A directory at the artifacts path makes the atomic rename fail with a
// raw fs error (EISDIR/ENOTEMPTY), not an ENOENT the code handles.
await mkdir(path.join(tmpDir, "caatinga.artifacts.json"));

await expect(writeArtifacts(createInitialArtifacts("app"), tmpDir)).rejects.toBeInstanceOf(
CaatingaError
);
});

it("readArtifacts wraps a raw read failure", async () => {
tmpDir = await mkdtemp(path.join(os.tmpdir(), "caatinga-wrap-"));
// Reading the artifacts path when it is a directory throws EISDIR — a raw
// error distinct from the ENOENT (missing file) the code returns empty for.
await mkdir(path.join(tmpDir, "caatinga.artifacts.json"));

await expect(readArtifacts(tmpDir)).rejects.toMatchObject({
code: CaatingaErrorCode.UNEXPECTED_ERROR,
});
});
});
4 changes: 2 additions & 2 deletions packages/core/src/frontend/sync-frontend-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { readArtifacts } from "../artifacts/read-artifacts.js";
import type { CaatingaConfig } from "../config/config.schema.js";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { resolveNetwork } from "../networks/resolve-network.js";

export type SyncFrontendEnvOptions = {
Expand Down Expand Up @@ -35,7 +35,7 @@ async function readExistingEnv(envFile: string): Promise<string | undefined> {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
return undefined;
}
throw error;
throw toCaatingaError(error);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/stellar-cli/check-stellar-cli-version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { runCommand } from "../shell/run-command.js";
import {
evaluateStellarCliCompatibility,
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function checkStellarCliVersion(
);
}

throw error;
throw toCaatingaError(error);
}

const version = parseStellarCliVersion(rawOutput);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/templates/create-project-from-template.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cp, lstat, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
import path from "node:path";
import { z } from "zod";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode, toCaatingaError } from "../errors/CaatingaError.js";
import { readArtifacts } from "../artifacts/read-artifacts.js";
import { createInitialArtifacts, writeArtifacts } from "../artifacts/write-artifacts.js";
import {
Expand Down Expand Up @@ -67,7 +67,7 @@ async function ensureArtifacts(targetDir: string, projectName: string): Promise<
return;
}

throw error;
throw toCaatingaError(error);
}
}

Expand Down Expand Up @@ -109,7 +109,7 @@ async function readTemplateManifest(templateDir: string): Promise<TemplateManife
);
}

throw error;
throw toCaatingaError(error);
}
}

Expand Down