Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
improve error handling in simulator setup
  • Loading branch information
emnul committed Dec 12, 2025
commit cd24f7e06ba6d6e49ce7ed69e29038b7926d0720
34 changes: 32 additions & 2 deletions packages/simulator/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Runs once before all tests via Vitest's globalSetup.
*/

import { exec } from 'node:child_process';
import { exec, type SpawnSyncReturns } from 'node:child_process';
import { existsSync, mkdirSync, statSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand All @@ -23,6 +23,23 @@ const CONTRACT_FILES = [
'SampleZOwnable.compact',
];

function isSpawnSyncRet(
err: unknown,
): err is SpawnSyncReturns<string | Buffer> {
if (typeof err !== "object" || err === null) {
return false;
}

const typedErr = err as Partial<SpawnSyncReturns<string | Buffer>> & Record<string, unknown>;

const okErr = typedErr.error instanceof Error;
const okStdout = typeof typedErr.stdout === "string" || Buffer.isBuffer(typedErr.stdout);
const okStderr = typeof typedErr.stderr === "string" || Buffer.isBuffer(typedErr.stderr);
const okStatus = typeof typedErr.status === "number" || typedErr.status === null;

return okErr && okStdout && okStderr && okStatus;
}

async function compileContract(contractFile: string): Promise<void> {
const inputPath = join(SAMPLE_CONTRACTS_DIR, contractFile);
const contractName = contractFile.replace('.compact', '');
Expand All @@ -48,7 +65,20 @@ async function compileContract(contractFile: string): Promise<void> {
mkdirSync(join(outputDir, 'keys'), { recursive: true });

const command = `compact compile --skip-zk "${inputPath}" "${outputDir}"`;
await execAsync(command);
try {
await execAsync(command);
} catch (err: unknown) {
if (!isSpawnSyncRet(err)) {
throw err;
}

if (err.status === 127) {
throw new Error("`compact` not found (exit code 127). Is it installed and on PATH?");
}

throw err;
}

console.log(`✓ Compiled ${contractFile}`);
}

Expand Down
Loading