-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exit process with error code when reporters fail #9735
Conversation
@@ -113,6 +113,7 @@ export default class ReporterRunner { | |||
}); | |||
} catch (reportError) { | |||
INTERNAL_ORIGINAL_CONSOLE.error(reportError); | |||
process.exitCode = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it is unexpected to do this for people using the Parcel programmatic API rather than our CLI? Should we store our own property here (rather than setting the global exit code), and then throw/emit an error from the main Parcel object that the CLI could pick up? We do already set an exit code in the CLI when an error is thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we just removed this catch
and let the error propagate naturally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to avoid propagating the errors because not all of the calls are awaited on, and doing so could regress performance.
As for storing something that the CLI can pickup, I can try doing that but it will only get emitted at the end of the build unless the aforementioned un-awaited cases are changed.
Alternatively, I could only propagate and await on buildSuccess events as that's the main use-case anyway.
Anyways the latest commit throws any received errors just before returning the build success event. I also initialise the reporters earlier so errors are seen earlier + adding to them becomes simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simplify this fixutre by using fsFixture
- example of an integration test with a reporter using fsFixture:
parcel/packages/core/integration-tests/test/api.js
Lines 62 to 109 in 89a69f5
describe('Reporter API', () => { | |
it('should pass the parcel version to plugins', async () => { | |
const dir = path.join(__dirname, 'plugin-parcel-version'); | |
overlayFS.mkdirp(dir); | |
await fsFixture(overlayFS, dir)` | |
index.js: | |
export default 'Hi'; | |
.parcelrc: | |
{ | |
extends: "@parcel/config-default", | |
reporters: ["./reporter-plugin.js", "..."], | |
} | |
package.json: | |
{ | |
"version": "1234" | |
} | |
yarn.lock: | |
reporter-plugin.js: | |
import {Reporter} from '@parcel/plugin'; | |
import path from 'node:path'; | |
export default new Reporter({ | |
async report({event, options}) { | |
if (event.type === 'buildSuccess') { | |
await options.outputFS.writeFile(path.join(options.projectRoot, 'parcel-version.txt'), options.parcelVersion); | |
} | |
} | |
}) | |
`; | |
await bundle(path.join(dir, 'index.js'), { | |
inputFS: overlayFS, | |
outputFS: overlayFS, | |
}); | |
assert.equal( | |
await overlayFS.readFile(path.join(dir, 'parcel-version.txt')), | |
PARCEL_VERSION, | |
); | |
}); | |
}); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially had an fs fixture, but want to test the CLI as well which requires the files to live on disk
0848df1
to
86aaf31
Compare
86aaf31
to
aeab6d4
Compare
|
||
module.exports = new Reporter({ | ||
async report({ event }) { | ||
if (event.type === 'buildSuccess') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd be nice to test for cases where there is a delay here
↪️ Pull Request
This change modifies the process exit code when a reporter fails, ensuring that builds do not pass when something goes wrong in a reporter (e.g. generating a file).
Adding this exit code is the simplest mechanism for failing the build, as it does not require changing the existing API or introducing new APIs.
🚨 Test instructions
yarn test:integration