From dfe956ab3992a2a9741b87239bae48f9f02c72f9 Mon Sep 17 00:00:00 2001 From: John Knox Date: Fri, 18 Jan 2019 08:24:38 -0800 Subject: [PATCH] Fix RecurringError::toString Summary: RecurringError::toString wasn't including the message. Fixed. Reviewed By: passy Differential Revision: D13732258 fbshipit-source-id: 71f5edef19de4e59d1c6c5bd549822871e36ede4 --- src/utils/__tests__/errors.node.js | 16 ++++++++++++++++ src/utils/errors.js | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 src/utils/__tests__/errors.node.js diff --git a/src/utils/__tests__/errors.node.js b/src/utils/__tests__/errors.node.js new file mode 100644 index 000000000..645c3cd67 --- /dev/null +++ b/src/utils/__tests__/errors.node.js @@ -0,0 +1,16 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +import {RecurringError} from '../errors'; + +test('Check RecurringError toString output', () => { + const error = new RecurringError('something'); + expect(error.toString()).toBe('[RecurringError] something'); + /* $FlowFixMe intentionally coercing it to a string to make sure the correct + method is overridden */ + expect('' + error).toBe('[RecurringError] something'); +}); diff --git a/src/utils/errors.js b/src/utils/errors.js index eca461f07..92d28578a 100644 --- a/src/utils/errors.js +++ b/src/utils/errors.js @@ -11,4 +11,7 @@ export class RecurringError extends Error { super(message); this.name = 'RecurringError'; } + toString(): string { + return `[${this.name}] ${this.message}`; + } }