Skip to content

Commit

Permalink
chore(merge): Merge pull request ReactiveX#1778 from blesh/better-err…
Browse files Browse the repository at this point in the history
…or-messages

Better error messages
  • Loading branch information
benlesh authored Jun 17, 2016
2 parents c3ac852 + 77342e5 commit 97d43fe
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
13 changes: 13 additions & 0 deletions spec/helpers/testScheduler-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,25 @@ module.exports = function(suite) {
.replace(/\\n/g, '\n');
}

function deleteErrorNotificationStack(marble) {
const { notification } = marble;
if (notification) {
const { kind, exception } = notification;
if (kind === 'E' && exception instanceof Error) {
notification.exception = { name: exception.name, message: exception.message };
}
}
return marble;
}

/**
* custom assertion formatter for expectObservable test
*/

function observableMatcher(actual, expected) {
if (Array.isArray(actual) && Array.isArray(expected)) {
actual = actual.map(deleteErrorNotificationStack);
expected = expected.map(deleteErrorNotificationStack);
const passed = _.isEqual(actual, expected);
if (passed) {
return;
Expand Down
6 changes: 3 additions & 3 deletions spec/util/UnsubscriptionError-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ describe('UnsubscriptionError', () => {
} catch (err) {
expect(err instanceof UnsubscriptionError).to.equal(true);
expect(err.message).to.equal(`2 errors occurred during unsubscription:
1) ${err1}
2) ${err2}`);
1) ${err1}
2) ${err2}`);
expect(err.name).to.equal('UnsubscriptionError');
}
});
});
});
8 changes: 5 additions & 3 deletions src/util/ArgumentOutOfRangeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
*/
export class ArgumentOutOfRangeError extends Error {
constructor() {
super('argument out of range');
this.name = 'ArgumentOutOfRangeError';
const err: any = super('argument out of range');
(<any> this).name = err.name = 'ArgumentOutOfRangeError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
}
8 changes: 5 additions & 3 deletions src/util/EmptyError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
*/
export class EmptyError extends Error {
constructor() {
super('no elements in sequence');
this.name = 'EmptyError';
const err: any = super('no elements in sequence');
(<any> this).name = err.name = 'EmptyError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
}
8 changes: 5 additions & 3 deletions src/util/ObjectUnsubscribedError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
*/
export class ObjectUnsubscribedError extends Error {
constructor() {
super('object unsubscribed');
this.name = 'ObjectUnsubscribedError';
const err: any = super('object unsubscribed');
(<any> this).name = err.name = 'ObjectUnsubscribedError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
}
11 changes: 7 additions & 4 deletions src/util/UnsubscriptionError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
export class UnsubscriptionError extends Error {
constructor(public errors: any[]) {
super();
this.name = 'UnsubscriptionError';
this.message = errors ? `${errors.length} errors occurred during unsubscription:
${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n')}` : '';
const err: any = Error.call(this, errors ?
`${errors.length} errors occurred during unsubscription:
${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : '');
(<any> this).name = err.name = 'UnsubscriptionError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
}

0 comments on commit 97d43fe

Please sign in to comment.