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
10 changes: 7 additions & 3 deletions packages/builder/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,13 @@ export class CompactCompiler {
UIService.printOutput(summary, chalk.cyan);
}

const cleanStderr = cleanForDisplay(execError.stderr);
if (cleanStderr) {
UIService.printOutput(cleanStderr, chalk.red);
// Under `script` the compiler's stderr is merged into the captured
// PTY output, so stdout is the only place the error text lives.
const details =
cleanForDisplay(execError.stderr) ||
cleanForDisplay(execError.stdout);
if (details) {
UIService.printOutput(details, chalk.red);
}
}

Expand Down
9 changes: 6 additions & 3 deletions packages/builder/src/services/CompilerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function tokenizeFlags(flags: string): string[] {
*
* Handles both macOS and Linux `script` syntax:
* - macOS: `script -q <file> <command> [args...]`
* - Linux: `script -qc "<command> [args...]" <file>`
* - Linux: `script -qec "<command> [args...]" <file>`
*
* util-linux `script` exits 0 whatever the child did unless `-e` is given.
* BSD `script` on macOS already returns the child's status.
*
* Note: Circuit constraint output is only available when compiling WITHOUT
* `--skip-zk`, as the k/rows values come from the ZK proving pass. When
Expand All @@ -61,11 +64,11 @@ async function spawnWithPty(
// macOS: script -q <file> <command> [args...]
scriptArgs = ['-q', tmpFile, 'compact', ...args];
} else {
// Linux: script -qc "<command>" <file>
// Linux: script -qec "<command>" <file>
const cmd = ['compact', ...args]
.map((a) => (a.includes(' ') ? `'${a}'` : a))
.join(' ');
scriptArgs = ['-qc', cmd, tmpFile];
scriptArgs = ['-qec', cmd, tmpFile];
}

const proc = spawn('script', scriptArgs, {
Expand Down
39 changes: 39 additions & 0 deletions packages/builder/test/Compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,45 @@ describe('CompactCompiler', () => {
);
expect(testMockExec).toHaveBeenCalledTimes(4);
});

it('prints the captured output when the failure carries no stderr', async () => {
mockReaddir.mockResolvedValue([
{
name: 'MockElGamal.compact',
isFile: () => true,
isDirectory: () => false,
},
] as any);
mockExistsSync.mockReturnValue(true);

const ptyError = new Error('compact exited with code 1') as Error & {
stdout: string;
stderr: string;
};
ptyError.stdout =
'Exception in thread "main" Unsupported test_eq: JubjubScalar == JubjubScalar\n';
ptyError.stderr = '';

const testMockExec = vi
.fn()
.mockResolvedValueOnce({ stdout: 'compact 0.1.0', stderr: '' })
.mockResolvedValueOnce({ stdout: 'compact 0.1.0', stderr: '' })
.mockResolvedValueOnce({ stdout: 'Compactc 0.26.0', stderr: '' })
.mockRejectedValueOnce(ptyError);

const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
compiler = new CompactCompiler({}, testMockExec);

await expect(compiler.compile()).rejects.toThrow(CompilationError);

expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining(
'Unsupported test_eq: JubjubScalar == JubjubScalar',
),
);

logSpy.mockRestore();
});
});

describe('Real-world scenarios', () => {
Expand Down
Loading