Skip to content

Convert @bugsnag/core/lib/iserror to TypeScript #2422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: integration/typescript
Choose a base branch
from
Open
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"./lib/validators/int-range": "./src/lib/validators/int-range.js",
"./lib/es-utils/includes": "./src/lib/es-utils/includes.js",
"./lib/es-utils/filter": "./src/lib/es-utils/filter.js",
"./lib/iserror": "./src/lib/iserror.js",
"./lib/es-utils/reduce": "./src/lib/es-utils/reduce.js",
"./lib/es-utils/keys": "./src/lib/es-utils/keys.js",
"./lib/derecursify": "./src/lib/derecursify.js",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export { default as Event } from './event'
export { default as Session } from './session'
export { default as schema } from './config'
export { default as cloneClient } from './lib/clone-client'
export { default as isError } from './lib/iserror'

export * from './common'
1 change: 0 additions & 1 deletion packages/core/src/lib/iserror.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/src/lib/iserror.js

This file was deleted.

36 changes: 36 additions & 0 deletions packages/core/src/lib/iserror.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// MIT License

// Copyright (c) 2017 Anton Yefremov

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

const isError = (maybeError: unknown): maybeError is Error => {
switch (Object.prototype.toString.call(maybeError)) {
case '[object Error]':
return true
case '[object Exception]':
return true
case '[object DOMException]':
return true
default:
return maybeError instanceof Error
}
}

export default isError
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Config, Plugin } from '@bugsnag/core'
import isError from '@bugsnag/core/lib/iserror'
import { isError, Config, Plugin } from '@bugsnag/core'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { isError, Config, Plugin } from '@bugsnag/core'
import { isError } from '@bugsnag/core'
import type { Config, Plugin } from '@bugsnag/core'

import fixBluebirdStacktrace from './fix-bluebird-stacktrace'

type Listener = (evt: PromiseRejectionEvent) => void
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native/src/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { schema } = require('@bugsnag/core')
const { iserror, schema } = require('@bugsnag/core')
const stringWithLength = require('@bugsnag/core/lib/validators/string-with-length')
const rnPackage = require('react-native/package.json')
const iserror = require('iserror')

const ALLOWED_IN_JS = [
'onError',
Expand Down