How can I throw an error from a plugin to prevent a build?
See original GitHub issue❔ Question
How can I throw an error in a plugin that will prevent the build from continuing?
🔦 Context
I am developing a one-liner plugin whose only job is to run execSync('tsc --noEmit')
before every build. It throws an error, and a warning is printed to the console, but the build continues on anyway. I can manually call process.exit(1)
but that’ll kill the whole parcel
process watching my files. Is it possible for a plugin to indicate that the build has failed?
💻 Code Sample
const { execSync } = require('child_process')
const path = require('path')
const cwd = process.cwd()
const binPath = execSync('yarn bin', { cwd, encoding: 'utf8' }).trim()
const tscCommand = `${path.join(binPath, 'tsc')} --noEmit`
module.exports = () => {
// Will throw if tsc reports any issues
execSync(tscCommand, { cwd, encoding: 'utf8', stdio: 'inherit' })
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Handle exceptions in plug-ins - Power Apps - Microsoft Learn
We recommend that you catch any error and throw an InvalidPluginExecutionException exception so you can control what is displayed to the user.
Read more >How to prevent build failure with custom Maven Plugin?
If you want, you can catch all exceptions in the execute method and discard them. But is it really sensible to ignore everything...
Read more >Dynamics 365 Raise Error in Plugin - Carl de Souza
To raise an error in the plugin code, we use InvalidPluginExecutionException. For example: throw new InvalidPluginExecutionException("Plugin ...
Read more >Exception Best Practice | Softchief Learn
If you throw InvalidPluginExecutionException and do not provide a custom message, a generic default message is displayed in the error dialog ...
Read more >Webpack client does not throw error code when build failed
I'd like to avoid to search for "ERROR" inside the client output to determine that the build failed. Thanks.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This makes it on every rebuild (“before”/“when”), but you can’t abort a build.
buildStart
worked perfectly, thanks!If anyone happens to be looking for a full list of events, they’re all very neatly defined at https://github.com/parcel-bundler/parcel/blob/23ba2cc54f3286f60e2cab63eb358660c916139d/packages/core/types/index.js