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
10 changes: 8 additions & 2 deletions packages/core/src/stellar-cli/check-stellar-cli-version.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { CaatingaErrorCode } from "../errors/CaatingaError.js";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";

const runCommandMock = vi.hoisted(() => vi.fn());

Expand Down Expand Up @@ -83,7 +83,13 @@ describe("checkStellarCliVersion", () => {
});

it("normalizes missing stellar binary to CAATINGA_STELLAR_CLI_NOT_FOUND", async () => {
runCommandMock.mockRejectedValueOnce(Object.assign(new Error("not found"), { code: "ENOENT" }));
runCommandMock.mockRejectedValueOnce(
new CaatingaError(
"Stellar CLI was not found.",
CaatingaErrorCode.STELLAR_CLI_NOT_FOUND,
"Install Stellar CLI before running Caatinga-backed commands."
)
);

await expect(checkStellarCliVersion()).rejects.toMatchObject({
code: CaatingaErrorCode.STELLAR_CLI_NOT_FOUND,
Expand Down
22 changes: 4 additions & 18 deletions packages/core/src/stellar-cli/check-stellar-cli-version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { runCommand } from "../shell/run-command.js";
import {
evaluateStellarCliCompatibility,
Expand All @@ -21,23 +20,10 @@ export async function checkStellarCliVersion(
): Promise<CompatibilityReport> {
let rawOutput: string;

try {
const result = await runCommand("stellar", ["--version"], {
skipStellarVersionCheck: true,
});
rawOutput = result.all || result.stdout || result.stderr;
} catch (error) {
if (typeof error === "object" && error && "code" in error && error.code === "ENOENT") {
throw new CaatingaError(
"Stellar CLI was not found.",
CaatingaErrorCode.STELLAR_CLI_NOT_FOUND,
"Install Stellar CLI before running Caatinga-backed commands.",
error
);
}

throw error;
}
const result = await runCommand("stellar", ["--version"], {
skipStellarVersionCheck: true,
});
rawOutput = result.all || result.stdout || result.stderr;

const version = parseStellarCliVersion(rawOutput);
const probedMissing =
Expand Down