Skip to content

Commit d7854fd

Browse files
authored
Do not allow overriding an error status with a success status (#1273)
1 parent 583a253 commit d7854fd

File tree

6 files changed

+101
-1
lines changed

6 files changed

+101
-1
lines changed

packages/build/src/core/status.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ const addStatus = function({ newStatus, statuses, event, package, packageJson: {
2727
return statuses
2828
}
2929

30+
// Error statuses cannot be overwritten
31+
const formerStatus = statuses.find(status => status.package === package)
32+
if (formerStatus !== undefined && formerStatus.state !== 'success') {
33+
return statuses
34+
}
35+
3036
// Overrides plugin's previous status and add more information
31-
const newStatuses = statuses.filter(status => status.package !== package)
37+
const newStatuses = statuses.filter(status => status !== formerStatus)
3238
return [...newStatuses, { ...newStatus, event, package, version }]
3339
}
3440

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[plugins]]
2+
package = "./plugin.js"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
onBuild() {
3+
throw new Error('onBuild')
4+
},
5+
onError({
6+
utils: {
7+
status: { show },
8+
},
9+
}) {
10+
show({ summary: 'summary' })
11+
},
12+
onEnd({
13+
utils: {
14+
status: { show },
15+
},
16+
}) {
17+
show({ summary: 'summary' })
18+
},
19+
}

packages/build/tests/plugins/status/snapshots/tests.js.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,75 @@ Generated by [AVA](https://ava.li).
306306
In "onInit" event in local plugin "/file/path"␊
307307
`
308308

309+
## utils.status.show() cannot override an error status
310+
311+
> Snapshot 1
312+
313+
`␊
314+
┌─────────────────────────────┐␊
315+
│ Netlify Build │␊
316+
└─────────────────────────────┘␊
317+
318+
> Version␊
319+
@netlify/build 1.0.0␊
320+
321+
> Flags␊
322+
repositoryRoot: /file/path␊
323+
324+
> Current directory␊
325+
/file/path␊
326+
327+
> Config file␊
328+
/file/path␊
329+
330+
> Resolved config␊
331+
plugins:␊
332+
- package: /file/path␊
333+
334+
> Context␊
335+
production␊
336+
337+
> Loading plugins␊
338+
- /file/path␊
339+
340+
┌─────────────────────────────────────┐␊
341+
│ 1. onBuild command from /file/path │␊
342+
└─────────────────────────────────────┘␊
343+
344+
345+
┌─────────────────────────────────────┐␊
346+
│ 2. onError command from /file/path │␊
347+
└─────────────────────────────────────┘␊
348+
349+
350+
(/file/path onError completed in 1ms)␊
351+
352+
┌───────────────────────────────────┐␊
353+
│ 3. onEnd command from /file/path │␊
354+
└───────────────────────────────────┘␊
355+
356+
357+
(/file/path onEnd completed in 1ms)␊
358+
359+
┌─────────────────────────────────────┐␊
360+
│ Plugin "/file/path" internal error │␊
361+
└─────────────────────────────────────┘␊
362+
363+
Error message␊
364+
Error: onBuild␊
365+
366+
Plugin details␊
367+
Name: /file/path␊
368+
Version: 1.0.0␊
369+
Repository: git+https://github.com/netlify/build.git␊
370+
npm link: https://www.npmjs.com/package/@netlify/build␊
371+
Report issues: https://github.com/netlify/build/issues␊
372+
373+
Error location␊
374+
In "onBuild" event in local plugin "/file/path"␊
375+
STACK TRACE␊
376+
`
377+
309378
## utils.status.show() does not fail
310379

311380
> Snapshot 1
Binary file not shown.

packages/build/tests/plugins/status/tests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ test('utils.status.show() are printed locally', async t => {
1414
await runFixture(t, 'print')
1515
})
1616

17+
test('utils.status.show() cannot override an error status', async t => {
18+
await runFixture(t, 'error_status_override')
19+
})
20+
1721
test('utils.status.show() argument should be defined', async t => {
1822
await runUtilsStatusShow(t, '')
1923
})

0 commit comments

Comments
 (0)