Skip to content

Commit e4c8b61

Browse files
committed
chore: bring back errors
1 parent bb2ff1b commit e4c8b61

2 files changed

Lines changed: 41 additions & 40 deletions

File tree

packages/shared/src/config/output/__tests__/postprocess.test.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,42 +122,44 @@ describe('postprocessOutput', () => {
122122
).toThrow('Post-processor "My Formatter" failed to run: spawnSync my-formatter ENOENT');
123123
});
124124

125-
it('should silently ignore non-zero exit codes', () => {
126-
mockSync.mockReturnValue({
127-
error: undefined,
128-
status: 1,
129-
stderr: Buffer.from('some error'),
130-
} as any);
131-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
132-
133-
postprocessOutput(
134-
{ ...baseConfig, postProcess: [{ args: ['{{path}}'], command: 'prettier' }] },
135-
noopPostProcessors,
136-
'',
137-
);
125+
it('should throw ConfigError when the process exits with a non-zero status code', () => {
126+
mockSync.mockReturnValue({ error: undefined, status: 1, stderr: Buffer.from('') } as any);
138127

139-
expect(warnSpy).not.toHaveBeenCalled();
140-
warnSpy.mockRestore();
128+
expect(() =>
129+
postprocessOutput(
130+
{ ...baseConfig, postProcess: [{ args: ['{{path}}'], command: 'prettier' }] },
131+
noopPostProcessors,
132+
'',
133+
),
134+
).toThrow(ConfigError);
141135
});
142136

143-
it('should continue processing after a non-zero exit code', () => {
144-
mockSync
145-
.mockReturnValueOnce({ error: undefined, status: 1, stderr: Buffer.from('') } as any)
146-
.mockReturnValueOnce({ error: undefined, status: 0 } as any);
137+
it('should include exit code in error message', () => {
138+
mockSync.mockReturnValue({ error: undefined, status: 1, stderr: Buffer.from('') } as any);
147139

148-
postprocessOutput(
149-
{
150-
...baseConfig,
151-
postProcess: [
152-
{ args: ['{{path}}'], command: 'first' },
153-
{ args: ['{{path}}'], command: 'second' },
154-
],
155-
},
156-
noopPostProcessors,
157-
'',
158-
);
140+
expect(() =>
141+
postprocessOutput(
142+
{ ...baseConfig, postProcess: [{ args: ['{{path}}'], command: 'prettier' }] },
143+
noopPostProcessors,
144+
'',
145+
),
146+
).toThrow('Post-processor "prettier" exited with code 1');
147+
});
159148

160-
expect(mockSync).toHaveBeenCalledTimes(2);
149+
it('should include stderr output in error message when process fails', () => {
150+
mockSync.mockReturnValue({
151+
error: undefined,
152+
status: 2,
153+
stderr: Buffer.from('error: file not found'),
154+
} as any);
155+
156+
expect(() =>
157+
postprocessOutput(
158+
{ ...baseConfig, postProcess: [{ args: ['{{path}}'], command: 'biome' }] },
159+
noopPostProcessors,
160+
'',
161+
),
162+
).toThrow('Post-processor "biome" exited with code 2:\nerror: file not found');
161163
});
162164

163165
it('should not throw when the process is killed by a signal (null status)', () => {

packages/shared/src/config/output/postprocess.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ export function postprocessOutput(
5454
postProcessors: Record<string, PostProcessor>,
5555
jobPrefix: string,
5656
): void {
57-
if (!config.postProcess.length) {
58-
return;
59-
}
60-
61-
// skip post-processing when the output directory doesn't exist or is empty
6257
if (!fs.existsSync(config.path) || fs.readdirSync(config.path).length === 0) {
6358
return;
6459
}
@@ -79,9 +74,13 @@ export function postprocessOutput(
7974
throw new ConfigError(`Post-processor "${name}" failed to run: ${result.error.message}`);
8075
}
8176

82-
// non-zero exit codes are silently ignored — post-processors like
83-
// ESLint and Oxfmt exit non-zero for non-fatal reasons (e.g. all
84-
// files ignored, no matching files) and warnings break CI pipelines
85-
// that treat any stderr output as an error
77+
if (result.status !== null && result.status !== 0) {
78+
let message = `Post-processor "${name}" exited with code ${result.status}`;
79+
const stderr = result.stderr?.toString().trim();
80+
if (stderr) {
81+
message += `:\n${stderr}`;
82+
}
83+
throw new ConfigError(message);
84+
}
8685
}
8786
}

0 commit comments

Comments
 (0)