Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Also, check the [example](example) directory.
environments)
* `debug [optional]` - `boolean`, print some useful debug information
* `silent [optional]` - `boolean`, if `true`, all logs are suppressed (useful for `--json` option)
* `errorHandler [optional]` - `function(err: Error, invokeErr: function(): void): void`, when Cli error occurs, plugin calls this function. webpack compilation failure can be chosen by calling `invokeErr` callback or not. default `(err, invokeErr) => { invokeErr() }`

You can find more information about these options in our official docs:
https://docs.sentry.io/cli/releases/#sentry-cli-sourcemaps
24 changes: 24 additions & 0 deletions src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,30 @@ describe('afterEmitHook', () => {
done();
});
});

test('handles errors with errorHandler option', done => {
expect.assertions(3);
mockCli.releases.new.mockImplementationOnce(() =>
Promise.reject(new Error('Pickle Rick'))
);
let e;

const sentryCliPlugin = new SentryCliPlugin({
include: 'src',
release: 42,
errorHandler: err => {
e = err;
},
});
sentryCliPlugin.apply(compiler);

setImmediate(() => {
expect(compilation.errors).toEqual([]);
expect(e.message).toEqual('Pickle Rick');
expect(compilationDoneCallback).toBeCalled();
done();
});
});
});

describe('module rule overrides', () => {
Expand Down
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,12 @@ class SentryCliPlugin {

/** Creates and finalizes a release on Sentry. */
finalizeRelease(compilation) {
const { include } = this.options;
const {
include,
errorHandler = (err, invokeErr) => {
invokeErr();
},
} = this.options;

if (!include) {
addCompilationError(compilation, '`include` option is required');
Expand All @@ -313,7 +318,9 @@ class SentryCliPlugin {
})
.then(() => this.cli.releases.uploadSourceMaps(release, this.options))
.then(() => this.cli.releases.finalize(release))
.catch(err => addCompilationError(compilation, err.message));
.catch(err =>
errorHandler(err, () => addCompilationError(compilation, err.message))
);
}

/** Webpack lifecycle hook to update compiler options. */
Expand Down