Skip to content

Commit 94b26ef

Browse files
pullfrog[bot]mrlubos
authored andcommitted
fix: warn on post-processor non-zero exit instead of throwing
Post-processors like ESLint and Oxfmt can exit non-zero for non-fatal reasons (e.g. all files ignored, no matching files). Previously these were silently swallowed; the prior commit made them throw ConfigError which broke examples:generate for openapi-ts-nestjs and openapi-ts-openai. Now non-zero exits log a warning and continue processing. Spawn failures (ENOENT) still throw as intended by the original fix.
1 parent ef151a0 commit 94b26ef

2 files changed

Lines changed: 46 additions & 28 deletions

File tree

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

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

125-
it('should throw ConfigError when the process exits with a non-zero status code', () => {
125+
it('should warn when the process exits with a non-zero status code', () => {
126126
mockSync.mockReturnValue({ error: undefined, status: 1, stderr: Buffer.from('') } as any);
127+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
127128

128-
expect(() =>
129-
postprocessOutput(
130-
{ ...baseConfig, postProcess: [{ args: ['{{path}}'], command: 'prettier' }] },
131-
noopPostProcessors,
132-
'',
133-
),
134-
).toThrow(ConfigError);
135-
});
136-
137-
it('should include exit code in error message', () => {
138-
mockSync.mockReturnValue({ error: undefined, status: 1, stderr: Buffer.from('') } as any);
129+
postprocessOutput(
130+
{ ...baseConfig, postProcess: [{ args: ['{{path}}'], command: 'prettier' }] },
131+
noopPostProcessors,
132+
'',
133+
);
139134

140-
expect(() =>
141-
postprocessOutput(
142-
{ ...baseConfig, postProcess: [{ args: ['{{path}}'], command: 'prettier' }] },
143-
noopPostProcessors,
144-
'',
145-
),
146-
).toThrow('Post-processor "prettier" exited with code 1');
135+
expect(warnSpy).toHaveBeenCalledWith(
136+
expect.stringContaining('Post-processor "prettier" exited with code 1'),
137+
);
138+
warnSpy.mockRestore();
147139
});
148140

149-
it('should include stderr output in error message when process fails', () => {
141+
it('should include stderr in warning when process exits with non-zero status', () => {
150142
mockSync.mockReturnValue({
151143
error: undefined,
152144
status: 2,
153145
stderr: Buffer.from('error: file not found'),
154146
} as any);
147+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
155148

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');
149+
postprocessOutput(
150+
{ ...baseConfig, postProcess: [{ args: ['{{path}}'], command: 'biome' }] },
151+
noopPostProcessors,
152+
'',
153+
);
154+
155+
expect(warnSpy).toHaveBeenCalledTimes(1);
156+
const warnArg = warnSpy.mock.calls[0]![0] as string;
157+
expect(warnArg).toContain('Post-processor "biome" exited with code 2:');
158+
expect(warnArg).toContain('error: file not found');
159+
warnSpy.mockRestore();
160+
});
161+
162+
it('should continue processing after a non-zero exit code', () => {
163+
mockSync
164+
.mockReturnValueOnce({ error: undefined, status: 1, stderr: Buffer.from('') } as any)
165+
.mockReturnValueOnce({ error: undefined, status: 0 } as any);
166+
vi.spyOn(console, 'warn').mockImplementation(() => {});
167+
168+
postprocessOutput(
169+
{
170+
...baseConfig,
171+
postProcess: [
172+
{ args: ['{{path}}'], command: 'first' },
173+
{ args: ['{{path}}'], command: 'second' },
174+
],
175+
},
176+
noopPostProcessors,
177+
'',
178+
);
179+
180+
expect(mockSync).toHaveBeenCalledTimes(2);
163181
});
164182

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function postprocessOutput(
8585
if (stderr) {
8686
message += `:\n${stderr}`;
8787
}
88-
throw new ConfigError(message);
88+
console.warn(`${jobPrefix}${colors.yellow(`⚠️ ${message}`)}`);
8989
}
9090
}
9191
}

0 commit comments

Comments
 (0)