Skip to content

Commit 1c0082f

Browse files
authored
feat: throw error on deploy command if build fails and user has --json option (#7367)
* feat: throw error on deploy command if build fails and user has --json option * test: Add test * chore: format
1 parent d81b990 commit 1c0082f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/commands/deploy/deploy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ const handleBuild = async ({
586586
deployHandler,
587587
})
588588
const { configMutations, exitCode, newConfig } = await runBuild(resolvedOptions)
589+
// Without this, the deploy command fails silently
590+
if (options.json && exitCode !== 0) {
591+
logAndThrowError('Error while running build')
592+
}
589593
if (exitCode !== 0) {
590594
exit(exitCode)
591595
}

tests/integration/commands/deploy/deploy.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,33 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
449449
})
450450
})
451451

452+
test('should throw error when build fails with --json option', async (t) => {
453+
await withSiteBuilder(t, async (builder) => {
454+
builder
455+
.withContentFile({
456+
path: 'public/index.html',
457+
content: '<h1>Test content</h1>',
458+
})
459+
.withNetlifyToml({
460+
config: {
461+
build: {
462+
publish: 'public',
463+
command: 'exit 1',
464+
},
465+
},
466+
})
467+
468+
await builder.build()
469+
470+
await expect(
471+
callCli(['deploy', '--json'], {
472+
cwd: builder.directory,
473+
env: { NETLIFY_SITE_ID: context.siteId },
474+
}),
475+
).rejects.toThrow('Error while running build')
476+
})
477+
})
478+
452479
test('should deploy hidden public folder but ignore hidden/__MACOSX files', { retry: 3 }, async (t) => {
453480
await withSiteBuilder(t, async (builder) => {
454481
builder

0 commit comments

Comments
 (0)