diff --git a/docs/02-javascript-api.md b/docs/02-javascript-api.md index 4a19bc5d86c..e59df36eb0b 100755 --- a/docs/02-javascript-api.md +++ b/docs/02-javascript-api.md @@ -12,6 +12,8 @@ On a `bundle` object, you can call `bundle.generate` multiple times with differe Once you're finished with the `bundle` object, you should call `bundle.close()`, which will let plugins clean up their external processes or services via the [`closeBundle`](guide/en/#closebundle) hook. +If an error occurs at either stage, it will return a Promise rejected with an Error, which you can identify via their `code` property. Besides `code` and `message`, many errors have additional properties you can use for custom reporting, see [`utils/error.ts`](https://github.com/rollup/rollup/blob/master/src/utils/error.ts) for a complete list of errors and warnings together with their codes and properties. + ```javascript import { rollup } from 'rollup'; diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 0017841bfd1..4397339e004 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -370,7 +370,7 @@ Type: `(warning: RollupWarning, defaultHandler: (warning: string | RollupWarning A function that will intercept warning messages. If not supplied, warnings will be deduplicated and printed to the console. When using the [`--silent`](guide/en/#--silent) CLI option, this handler is the only way to get notified about warnings. -The function receives two arguments: the warning object and the default handler. Warnings objects have, at a minimum, a `code` and a `message` property, allowing you to control how different kinds of warnings are handled. Other properties are added depending on the type of warning. +The function receives two arguments: the warning object and the default handler. Warnings objects have, at a minimum, a `code` and a `message` property, allowing you to control how different kinds of warnings are handled. Other properties are added depending on the type of warning. See [`utils/error.ts`](https://github.com/rollup/rollup/blob/master/src/utils/error.ts) for a complete list of errors and warnings together with their codes and properties. ```js // rollup.config.js @@ -381,7 +381,9 @@ export default { if (warning.code === 'UNUSED_EXTERNAL_IMPORT') return; // throw on others - if (warning.code === 'MISSING_EXPORT') throw new Error(warning.message); + // Using Object.assign over new Error(warning.message) will make the CLI + // print additional information such as warning location and help url. + if (warning.code === 'MISSING_EXPORT') throw Object.assign(new Error(), warning); // Use default for everything else warn(warning); diff --git a/package-lock.json b/package-lock.json index a23355874de..4ca8781da60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6238,9 +6238,9 @@ "dev": true }, "node_modules/terser": { - "version": "5.14.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.1.tgz", - "integrity": "sha512-+ahUAE+iheqBTDxXhTisdA8hgvbEG1hHOQ9xmNjeUJSoi6DU/gMrKNcfZjHkyY6Alnuyc+ikYJaxxfHkT3+WuQ==", + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz", + "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==", "dev": true, "dependencies": { "@jridgewell/source-map": "^0.3.2", @@ -11418,9 +11418,9 @@ "dev": true }, "terser": { - "version": "5.14.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.1.tgz", - "integrity": "sha512-+ahUAE+iheqBTDxXhTisdA8hgvbEG1hHOQ9xmNjeUJSoi6DU/gMrKNcfZjHkyY6Alnuyc+ikYJaxxfHkT3+WuQ==", + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz", + "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==", "dev": true, "requires": { "@jridgewell/source-map": "^0.3.2", diff --git a/rollup.config.ts b/rollup.config.ts index 0136660c52f..01783d5ca12 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -47,7 +47,7 @@ const onwarn: WarningHandlerWithDefault = warning => { 'Building Rollup produced warnings that need to be resolved. ' + 'Please keep in mind that the browser build may never have external dependencies!' ); - throw new Error(warning.message); + throw Object.assign(new Error(), warning); }; const moduleAliases = {