Skip to content

Commit 7d5787a

Browse files
Convert @bugsnag/core/lib/iserror to TypeScript (#2422)
* core: convert iserror to typescript * fix isError function * delete iserror from package.json * fix naming * delete iserror from rn package.json * delete iserror from all packages as it not used
1 parent bbcff4a commit 7d5787a

10 files changed

Lines changed: 43 additions & 29 deletions

File tree

package-lock.json

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"./lib/es-utils/assign": "./src/lib/es-utils/assign.js",
1313
"./lib/es-utils/includes": "./src/lib/es-utils/includes.js",
1414
"./lib/es-utils/filter": "./src/lib/es-utils/filter.js",
15-
"./lib/iserror": "./src/lib/iserror.js",
1615
"./lib/es-utils/reduce": "./src/lib/es-utils/reduce.js",
1716
"./lib/es-utils/keys": "./src/lib/es-utils/keys.js",
1817
"./lib/derecursify": "./src/lib/derecursify.js",
@@ -52,7 +51,6 @@
5251
"@bugsnag/cuid": "^3.0.0",
5352
"@bugsnag/safe-json-stringify": "^6.0.0",
5453
"error-stack-parser": "^2.0.3",
55-
"iserror": "^0.0.2",
5654
"stack-generator": "^2.0.3"
5755
},
5856
"devDependencies": {

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export { default as schema } from './config'
66
export { default as cloneClient } from './lib/clone-client'
77
export { default as jsonPayload } from './lib/json-payload'
88
export { default as intRange } from './lib/validators/int-range'
9+
export { default as isError } from './lib/iserror'
910

1011
export * from './common'

packages/core/src/lib/iserror.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/core/src/lib/iserror.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/core/src/lib/iserror.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// MIT License
2+
3+
// Copyright (c) 2017 Anton Yefremov
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
const isError = (maybeError: unknown): maybeError is Error => {
24+
switch (Object.prototype.toString.call(maybeError)) {
25+
case '[object Error]':
26+
return true
27+
case '[object Exception]':
28+
return true
29+
case '[object DOMException]':
30+
return true
31+
default:
32+
return maybeError instanceof Error
33+
}
34+
}
35+
36+
export default isError

packages/node/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"@bugsnag/core": "^8.2.0",
5151
"byline": "^5.0.0",
5252
"error-stack-parser": "^2.0.3",
53-
"iserror": "^0.0.2",
5453
"pump": "^3.0.0",
5554
"stack-generator": "^2.0.3"
5655
}

packages/plugin-window-unhandled-rejection/src/unhandled-rejection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Config, Plugin } from '@bugsnag/core'
2-
import isError from '@bugsnag/core/lib/iserror'
1+
import { isError } from '@bugsnag/core'
2+
import type { Config, Plugin } from '@bugsnag/core'
33
import fixBluebirdStacktrace from './fix-bluebird-stacktrace'
44

55
type Listener = (evt: PromiseRejectionEvent) => void

packages/react-native/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@
6464
"@bugsnag/plugin-react-native-global-error-handler": "^8.2.0",
6565
"@bugsnag/plugin-react-native-hermes": "^8.2.0",
6666
"@bugsnag/plugin-react-native-session": "^8.2.0",
67-
"@bugsnag/plugin-react-native-unhandled-rejection": "^8.2.0",
68-
"iserror": "^0.0.2"
67+
"@bugsnag/plugin-react-native-unhandled-rejection": "^8.2.0"
6968
},
7069
"scripts": {
7170
"prepare": "bash prepare-android-vendor.sh",

packages/react-native/src/config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const { schema } = require('@bugsnag/core')
1+
const { isError, schema } = require('@bugsnag/core')
22
const stringWithLength = require('@bugsnag/core/lib/validators/string-with-length')
33
const rnPackage = require('react-native/package.json')
4-
const iserror = require('iserror')
54

65
const ALLOWED_IN_JS = [
76
'onError',
@@ -64,7 +63,7 @@ const getPrefixedConsole = () => {
6463
accum[method] = (...args) => originalConsole[method]('[bugsnag]', ...args)
6564
} else {
6665
accum[method] = (...args) => {
67-
if (!iserror(args[0])) {
66+
if (!isError(args[0])) {
6867
originalConsole[method]('[bugsnag]', ...args)
6968
} else {
7069
// a raw error doesn't display nicely in react native's yellow box,

0 commit comments

Comments
 (0)