@honeybadger-io/react-native 5.2.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/README.md +54 -73
- package/dist/index.d.ts +20 -0
- package/dist/index.js +379 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -35
- package/index.d.ts +0 -61
- package/index.js +0 -657
- package/tsconfig.json +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,62 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [6.0.1](https://github.com/honeybadger-io/honeybadger-js/compare/@honeybadger-io/react-native@6.0.0...@honeybadger-io/react-native@6.0.1) (2023-06-08)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @honeybadger-io/react-native
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 6.0.0 (2023-06-07)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### ⚠ BREAKING CHANGES
|
|
18
|
+
|
|
19
|
+
* **react-native:** include the features of the core js project (#1069)
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* **react-native:** include the features of the core js project ([#1069](https://github.com/honeybadger-io/honeybadger-js/issues/1069)) ([a956508](https://github.com/honeybadger-io/honeybadger-js/commit/a956508272bdec340e6c93cf3e1f38ad4028cbfd))
|
|
24
|
+
|
|
25
|
+
## 5.2.0 (2023-03-27)
|
|
26
|
+
|
|
27
|
+
## 5.1.6 (2023-03-14)
|
|
28
|
+
|
|
29
|
+
## 5.1.4 (2023-02-27)
|
|
30
|
+
|
|
31
|
+
## 5.1.1 (2023-02-13)
|
|
32
|
+
|
|
33
|
+
## 5.0.0 (2023-02-05)
|
|
34
|
+
|
|
35
|
+
## 4.10.0 (2023-02-05)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### ⚠ BREAKING CHANGES
|
|
39
|
+
|
|
40
|
+
* specify "engines" in package.json
|
|
41
|
+
|
|
42
|
+
### Features
|
|
43
|
+
|
|
44
|
+
* **rollup-plugin:** add rollup/vite plugin that uploads sourcemaps to honeybadger API ([850b2b5](https://github.com/honeybadger-io/honeybadger-js/commit/850b2b5740d960e7e533b848c09c62a9bb9f63cb))
|
|
45
|
+
* specify "engines" in package.json ([d0eb1a3](https://github.com/honeybadger-io/honeybadger-js/commit/d0eb1a368b9904d464528a61844fa52416d14828)), closes [#961](https://github.com/honeybadger-io/honeybadger-js/issues/961)
|
|
46
|
+
|
|
47
|
+
## 4.8.2 (2023-01-02)
|
|
48
|
+
|
|
49
|
+
## 4.8.0 (2022-12-12)
|
|
50
|
+
|
|
51
|
+
## 4.7.1 (2022-11-14)
|
|
52
|
+
|
|
53
|
+
## 4.7.0 (2022-11-01)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Features
|
|
57
|
+
|
|
58
|
+
* migrate honeybadger-react-native to monorepo ([#901](https://github.com/honeybadger-io/honeybadger-js/issues/901)) ([46f3d7e](https://github.com/honeybadger-io/honeybadger-js/commit/46f3d7e0db7c4c18698fb2044802351efbbdbab9))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
6
62
|
## [5.2.0](https://github.com/honeybadger-io/honeybadger-js/compare/v5.1.7...v5.2.0) (2023-03-27)
|
|
7
63
|
|
|
8
64
|
**Note:** Version bump only for package @honeybadger-io/react-native
|
package/README.md
CHANGED
|
@@ -8,14 +8,14 @@ A React Native library for integrating [Honeybadger](https://honeybadger.io) int
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
From the root directory of your React Native project:
|
|
11
|
+
From the root directory of your React Native project, add *@honeybadger-io/react-native* as a dependency:
|
|
12
12
|
|
|
13
13
|
```shell
|
|
14
14
|
npm install "@honeybadger-io/react-native"
|
|
15
15
|
cd ios && pod install
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
The
|
|
18
|
+
The iOS step is required to properly add the library to the Xcode project through CocoaPods. Android doesn't require a separate step.
|
|
19
19
|
|
|
20
20
|
## Initialization
|
|
21
21
|
|
|
@@ -25,86 +25,32 @@ Add the following to your **App.js** file to initialize the Honeybadger library.
|
|
|
25
25
|
import Honeybadger from "@honeybadger-io/react-native";
|
|
26
26
|
|
|
27
27
|
export default function App() {
|
|
28
|
-
Honeybadger.configure(
|
|
28
|
+
Honeybadger.configure({
|
|
29
|
+
apiKey: '[ YOUR API KEY HERE ]'
|
|
30
|
+
})
|
|
29
31
|
// ...
|
|
30
32
|
}
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
You can log into your [Honeybadger](https://honeybadger.io) account to obtain your API key.
|
|
35
|
+
You can log into your [Honeybadger](https://app.honeybadger.io/) account to obtain your API key.
|
|
34
36
|
|
|
35
37
|
|
|
36
38
|
## Configuration
|
|
39
|
+
See the [Configuration Reference](https://docs.honeybadger.io/lib/javascript/reference/configuration/) for a full list of config options.
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
## Usage
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|--------------|---------|----------|---------|----------------------|
|
|
42
|
-
| apiKey | String | YES | `""` | `"hb-api-key-1234"` |
|
|
43
|
-
| reportErrors | Boolean | NO | true | |
|
|
44
|
-
| revision | String | NO | `""` | `"8afb34a"` |
|
|
45
|
-
| projectRoot | String | NO | `""` | `"/path/to/project"` |
|
|
43
|
+
Uncaught iOS, Android, and JavaScript errors will be automatically reported to Honeybadger by default.
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
Honeybadger.configure(
|
|
49
|
-
"hb-api-key-1234",
|
|
50
|
-
"8afb34a",
|
|
51
|
-
"/path/to/project"
|
|
52
|
-
);
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
The **reportErrors** parameter determines if errors are to be sent to Honeybadger. This is set to **true** by default. In certain environments, say, during development, it could be useful to set **reportErrors** to **false** to prevent errors from being posted to your Honeybadger account.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
## Usage Examples
|
|
59
|
-
|
|
60
|
-
iOS, Android, and JavaScript errors will be automatically handled by the Honeybadger React Native library, by default. But you can also use the following API to customize error handling in your application.
|
|
61
|
-
|
|
62
|
-
### Honeybadger.notify(error, additionalData)
|
|
63
|
-
|
|
64
|
-
You can use the **notify** method to send any kind of error, exception, object, String, etc. If sending an error or exception, the Honeybadger React Native library will attempt to extract a stack trace and any relevant information that might be useful. You can also optionally provide **additionalData** to the **notify** method, as either a string or an object, to include any relevant information.
|
|
65
|
-
|
|
66
|
-
### Honeybadger.setContext(context)
|
|
67
|
-
|
|
68
|
-
If you have data that you would like to include whenever an error or an exception occurs, you can provide that data using the **setContext** method. Provide an object as an argument. You can call **setContext** as many times as needed. New context data will be merged with any previously-set context data.
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
Honeybadger.setContext({
|
|
72
|
-
user_id: "123abc",
|
|
73
|
-
more: "some additional data",
|
|
74
|
-
});
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Honeybadger.resetContext()
|
|
78
|
-
|
|
79
|
-
If you've used **Honeybadger.setContext()** to store context data, you can use **Honeybadger.resetContext()** to clear that data.
|
|
80
|
-
|
|
81
|
-
### Honeybadger.setLogLevel(logLevel)
|
|
82
|
-
|
|
83
|
-
Sets the logging level for the Honeybadger library.
|
|
84
|
-
|
|
85
|
-
```js
|
|
86
|
-
Honeybadger.setLogLevel("debug");
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
The following values are accepted:
|
|
45
|
+
You can also [report errors](https://docs.honeybadger.io/lib/javascript/guides/reporting-errors/) yourself using `Honeybadger.notify()`.
|
|
90
46
|
|
|
91
|
-
|
|
92
|
-
|-----------|------------------------------------------|
|
|
93
|
-
| "debug" | Everything will be logged to console. |
|
|
94
|
-
| "warning" | Only warnings will be logged to console. |
|
|
95
|
-
| "error" | Only errors will be logged to console. |
|
|
47
|
+
Error reports can be [customized](https://docs.honeybadger.io/lib/javascript/guides/customizing-error-reports/), for example by using `Honeybadger.setContext()`, `Honeybadger.addBreadcrumb()`, and `Honeybadger.beforeNotify()`.
|
|
96
48
|
|
|
97
|
-
|
|
49
|
+
### Limitations
|
|
50
|
+
Some native errors on Android may not be recorded if they cause an immediate crash of the app before the notice makes it to Honeybadger.
|
|
98
51
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
This package includes a script that will help you generate source maps for your project. To generate source maps for both iOS and Android, run the following from your project root directory.
|
|
102
|
-
|
|
103
|
-
```shell
|
|
104
|
-
npx honeybadger-generate-sourcemaps
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
The operation might take some time, as React Native needs to build production-ready bundles and their respective source map files for both iOS and Android. Upon completion, you will find the **sourcemap-ios** and **sourcemap-android** files in your project root directory. You can then [upload these files to Honeybadger](https://docs.honeybadger.io/lib/javascript/guides/using-source-maps.html) to view descriptive stack trace symbols in your production builds.
|
|
52
|
+
### Source Maps
|
|
53
|
+
The procedure to generate and upload sourcemaps for react-native is currently [under development](https://github.com/honeybadger-io/honeybadger-js/issues/1029).
|
|
108
54
|
|
|
109
55
|
## Example Projects
|
|
110
56
|
|
|
@@ -113,19 +59,30 @@ The **examples** directory contains two minimal React Native projects, demonstra
|
|
|
113
59
|
### react-native-cli
|
|
114
60
|
```shell
|
|
115
61
|
npm install
|
|
116
|
-
|
|
117
|
-
|
|
62
|
+
npm run ios:install
|
|
63
|
+
npm start
|
|
118
64
|
```
|
|
119
65
|
In a new shell:
|
|
120
66
|
```
|
|
121
|
-
|
|
67
|
+
npm run ios
|
|
122
68
|
```
|
|
123
69
|
or
|
|
124
70
|
```
|
|
125
|
-
|
|
71
|
+
npm run android
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
If you want to test a release (ie prod) build, use
|
|
75
|
+
```shell
|
|
76
|
+
npm run ios:release
|
|
77
|
+
```
|
|
78
|
+
or
|
|
79
|
+
```shell
|
|
80
|
+
npm run android:release
|
|
126
81
|
```
|
|
127
82
|
|
|
128
83
|
### expo-app
|
|
84
|
+
Do not use `npx expo start`, since this relies on Expo Go, which [does not support custom native code](https://docs.expo.dev/bare/using-expo-client/). Instead, use the following commands:
|
|
85
|
+
|
|
129
86
|
```shell
|
|
130
87
|
npm install
|
|
131
88
|
npm run ios
|
|
@@ -138,6 +95,30 @@ npm run android
|
|
|
138
95
|
|
|
139
96
|
When the app opens, enter your API key, press "Configure", and then test your setup by using the button to throw an error.
|
|
140
97
|
|
|
98
|
+
If you want to test a release (ie prod) build, use
|
|
99
|
+
```shell
|
|
100
|
+
npm run ios:release
|
|
101
|
+
```
|
|
102
|
+
or
|
|
103
|
+
```shell
|
|
104
|
+
npm run android:release
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Development workflow
|
|
108
|
+
When developing the react-native package and testing against the example projects, you will need to change the dependency in the example project's `package.json`. Rather than `"@honeybadger-io/react-native": "latest"`, you'll want to generate a tarball of the `react-native` package and install it. For example:
|
|
109
|
+
|
|
110
|
+
In the `react-native` folder:
|
|
111
|
+
```shell
|
|
112
|
+
npm run build && npm pack
|
|
113
|
+
```
|
|
114
|
+
This will generate a tarball. Install it in an example project by updating `package.json`, for example:
|
|
115
|
+
```json
|
|
116
|
+
"@honeybadger-io/react-native": "file:../../honeybadger-io-react-native-5.1.6.tgz"
|
|
117
|
+
```
|
|
118
|
+
Then run `npm install` within the example project.
|
|
119
|
+
|
|
120
|
+
If you notice that your changes are not being picked up, there may be a caching issue. You can bust this by renaming the tarball to a unique name and re-installing it.
|
|
121
|
+
|
|
141
122
|
## License
|
|
142
123
|
|
|
143
124
|
The Honeybadger React Native library is MIT-licensed. See the [MIT-LICENSE](./MIT-LICENSE) file in this folder for details.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Client, Types } from '@honeybadger-io/core';
|
|
2
|
+
|
|
3
|
+
declare class Honeybadger extends Client {
|
|
4
|
+
private __jsHandlerInitialized;
|
|
5
|
+
private __nativeHandlerInitialized;
|
|
6
|
+
private __originalJsHandler;
|
|
7
|
+
constructor(opts?: Partial<Types.Config>);
|
|
8
|
+
configure(opts?: Partial<Types.Config>): this;
|
|
9
|
+
factory(opts?: Partial<Types.BrowserConfig>): this;
|
|
10
|
+
checkIn(): Promise<void>;
|
|
11
|
+
showUserFeedbackForm(): Promise<void>;
|
|
12
|
+
private setJavascriptErrorHandler;
|
|
13
|
+
private setNativeExceptionHandler;
|
|
14
|
+
private onNativeException;
|
|
15
|
+
private onNativeIOSException;
|
|
16
|
+
private onNativeAndroidException;
|
|
17
|
+
}
|
|
18
|
+
declare const _default: Honeybadger;
|
|
19
|
+
|
|
20
|
+
export { _default as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactNative = require('react-native');
|
|
4
|
+
var core = require('@honeybadger-io/core');
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
/* global Reflect, Promise */
|
|
21
|
+
|
|
22
|
+
var extendStatics = function(d, b) {
|
|
23
|
+
extendStatics = Object.setPrototypeOf ||
|
|
24
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
26
|
+
return extendStatics(d, b);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function __extends(d, b) {
|
|
30
|
+
if (typeof b !== "function" && b !== null)
|
|
31
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
32
|
+
extendStatics(d, b);
|
|
33
|
+
function __() { this.constructor = d; }
|
|
34
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var __assign = function() {
|
|
38
|
+
__assign = Object.assign || function __assign(t) {
|
|
39
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
+
s = arguments[i];
|
|
41
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
42
|
+
}
|
|
43
|
+
return t;
|
|
44
|
+
};
|
|
45
|
+
return __assign.apply(this, arguments);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
49
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
50
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
51
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
52
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
53
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
54
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function __generator(thisArg, body) {
|
|
59
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
60
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
61
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
62
|
+
function step(op) {
|
|
63
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
64
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
65
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
66
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
67
|
+
switch (op[0]) {
|
|
68
|
+
case 0: case 1: t = op; break;
|
|
69
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
70
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
71
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
72
|
+
default:
|
|
73
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
74
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
75
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
76
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
77
|
+
if (t[2]) _.ops.pop();
|
|
78
|
+
_.trys.pop(); continue;
|
|
79
|
+
}
|
|
80
|
+
op = body.call(thisArg, _);
|
|
81
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
82
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var name = "@honeybadger-io/react-native";
|
|
87
|
+
var version = "6.0.1";
|
|
88
|
+
var repository = {
|
|
89
|
+
type: "git",
|
|
90
|
+
url: "git@github.com:honeybadger-io/honeybadger-js.git"
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
var Transport = /** @class */ (function () {
|
|
94
|
+
function Transport() {
|
|
95
|
+
}
|
|
96
|
+
Transport.prototype.send = function (options, payload) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var params, res, resBody;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
payload.notifier = {
|
|
103
|
+
name: name,
|
|
104
|
+
url: repository.url,
|
|
105
|
+
version: version,
|
|
106
|
+
};
|
|
107
|
+
params = {
|
|
108
|
+
method: options.method,
|
|
109
|
+
headers: __assign(__assign({}, options.headers), { 'User-Agent': this.buildUserAgent() }),
|
|
110
|
+
body: JSON.stringify(core.Util.sanitize(payload, options.maxObjectDepth))
|
|
111
|
+
};
|
|
112
|
+
return [4 /*yield*/, fetch(options.endpoint, params)];
|
|
113
|
+
case 1:
|
|
114
|
+
res = _a.sent();
|
|
115
|
+
return [4 /*yield*/, res.text()];
|
|
116
|
+
case 2:
|
|
117
|
+
resBody = _a.sent();
|
|
118
|
+
return [2 /*return*/, {
|
|
119
|
+
statusCode: res.status,
|
|
120
|
+
body: resBody
|
|
121
|
+
}];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
Transport.prototype.buildUserAgent = function () {
|
|
127
|
+
var reactNativeVersion = reactNative.Platform.constants.reactNativeVersion.major + "." + reactNative.Platform.constants.reactNativeVersion.minor + "." + reactNative.Platform.constants.reactNativeVersion.patch;
|
|
128
|
+
var nativePlatform;
|
|
129
|
+
if (reactNative.Platform.OS === 'ios') {
|
|
130
|
+
var nativePlatformName = reactNative.Platform.constants.systemName || 'iOS';
|
|
131
|
+
nativePlatform = nativePlatformName + " " + reactNative.Platform.constants.osVersion;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
nativePlatform = 'Android';
|
|
135
|
+
}
|
|
136
|
+
return name + " " + version + "; " + reactNativeVersion + "; " + nativePlatform;
|
|
137
|
+
};
|
|
138
|
+
return Transport;
|
|
139
|
+
}());
|
|
140
|
+
|
|
141
|
+
function errorMessageFromIosException(data) {
|
|
142
|
+
if (!data) {
|
|
143
|
+
return '';
|
|
144
|
+
}
|
|
145
|
+
if (data.localizedDescription) {
|
|
146
|
+
var localizedDescription = data.localizedDescription;
|
|
147
|
+
var startOfNativeIOSCallStack = localizedDescription.indexOf('callstack: (\n');
|
|
148
|
+
if (startOfNativeIOSCallStack === -1) {
|
|
149
|
+
var lines = localizedDescription.split('\n');
|
|
150
|
+
return lines.length === 0 ? localizedDescription : lines[0].trim();
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return localizedDescription.substring(0, startOfNativeIOSCallStack).trim();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (data.name || data.reason) {
|
|
157
|
+
return (data.name + " : " + data.reason).trim();
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return '';
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function backtraceAndDetailsFromIosException(data) {
|
|
164
|
+
var framesFromComponent = framesFromComponentStack(data.localizedDescription);
|
|
165
|
+
var framesFromReactNativeIos = framesFromReactNativeIosStack(data);
|
|
166
|
+
var framesFromIosCall = framesFromIOSCallStack(data);
|
|
167
|
+
var backtrace = [];
|
|
168
|
+
var backtraceDetails = {};
|
|
169
|
+
if (framesFromComponent.length) {
|
|
170
|
+
backtrace = framesFromComponent;
|
|
171
|
+
backtraceDetails.primaryBackTraceSource = 'ReactNativeComponentStack';
|
|
172
|
+
if (framesFromReactNativeIos.length) {
|
|
173
|
+
backtraceDetails.reactNativeIOSStackTrace = framesFromReactNativeIos;
|
|
174
|
+
}
|
|
175
|
+
if (framesFromIosCall.length) {
|
|
176
|
+
backtraceDetails.iosCallStack = framesFromIosCall;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (framesFromReactNativeIos.length) {
|
|
180
|
+
backtrace = framesFromReactNativeIos;
|
|
181
|
+
backtraceDetails.primaryBackTraceSource = 'ReactNativeIOSStackTrace';
|
|
182
|
+
if (framesFromIosCall.length) {
|
|
183
|
+
backtraceDetails.iosCallStack = framesFromIosCall;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else if (framesFromIosCall.length) {
|
|
187
|
+
backtrace = framesFromIosCall;
|
|
188
|
+
backtraceDetails.primaryBackTraceSource = 'iOSCallStack';
|
|
189
|
+
}
|
|
190
|
+
return { backtrace: backtrace, backtraceDetails: backtraceDetails };
|
|
191
|
+
}
|
|
192
|
+
function framesFromComponentStack(str) {
|
|
193
|
+
str = str || '';
|
|
194
|
+
var frames = [];
|
|
195
|
+
var regex = /^\s*in\s(\S+)(\s\(at\s(\S+):(\S+)\)\s*$)?/gm;
|
|
196
|
+
var match;
|
|
197
|
+
while ((match = regex.exec(str)) !== null) {
|
|
198
|
+
if (match.index === regex.lastIndex) {
|
|
199
|
+
regex.lastIndex++;
|
|
200
|
+
}
|
|
201
|
+
frames.push({
|
|
202
|
+
method: match && match.length > 1 ? match[1] : '',
|
|
203
|
+
file: match && match.length > 3 ? match[3] : '',
|
|
204
|
+
number: match && match.length > 4 ? match[4] : '',
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return frames;
|
|
208
|
+
}
|
|
209
|
+
function framesFromReactNativeIosStack(data) {
|
|
210
|
+
if (!data.reactNativeStackTrace) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
return data.reactNativeStackTrace.map(function (frame) { return ({
|
|
214
|
+
method: frame.methodName || '',
|
|
215
|
+
number: frame.lineNumber || '',
|
|
216
|
+
file: frame.file || '',
|
|
217
|
+
column: frame.column || '',
|
|
218
|
+
}); });
|
|
219
|
+
}
|
|
220
|
+
function framesFromIOSCallStack(data) {
|
|
221
|
+
var callStack = [];
|
|
222
|
+
if (data.localizedDescription && typeof data.localizedDescription === 'string') {
|
|
223
|
+
callStack = data.localizedDescription.split('\n').map(function (item) { return item.trim(); });
|
|
224
|
+
}
|
|
225
|
+
else if (Array.isArray(data.callStackSymbols) && data.callStackSymbols.length) {
|
|
226
|
+
callStack = data.callStackSymbols.map(function (item) { return item.trim(); });
|
|
227
|
+
}
|
|
228
|
+
var frames = [];
|
|
229
|
+
var regex = /\d+\s+(\S+)\s+(\S+)\s(.+)\s\+\s(\d+)(\s+\((\S+):(\S+)\))?/gm;
|
|
230
|
+
var match;
|
|
231
|
+
callStack.forEach(function (element) {
|
|
232
|
+
while ((match = regex.exec(element)) !== null) {
|
|
233
|
+
if (match.index === regex.lastIndex) {
|
|
234
|
+
regex.lastIndex++;
|
|
235
|
+
}
|
|
236
|
+
var moduleName = match && match.length > 1 ? match[1] : '';
|
|
237
|
+
var stackAddress = match && match.length > 2 ? match[2] : '';
|
|
238
|
+
var loadAddress = match && match.length > 3 ? match[3] : '';
|
|
239
|
+
var file = match && match.length > 6 ? match[6] : '';
|
|
240
|
+
var line = match && match.length > 7 ? match[7] : '';
|
|
241
|
+
// TODO: Why doesn't this match the BacktraceFrame type?
|
|
242
|
+
frames.push({
|
|
243
|
+
file: file || moduleName || '',
|
|
244
|
+
line: line || '',
|
|
245
|
+
method: loadAddress || '',
|
|
246
|
+
stack_address: stackAddress || '',
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return frames;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function backtraceFromAndroidException(data) {
|
|
254
|
+
if (!data || !data.stackTrace)
|
|
255
|
+
return [];
|
|
256
|
+
function isStringWithValue(val) {
|
|
257
|
+
return typeof val === 'string' && val.trim().length > 0;
|
|
258
|
+
}
|
|
259
|
+
return data.stackTrace.map(function (frame) {
|
|
260
|
+
var method = (isStringWithValue(frame.class) && isStringWithValue(frame.method))
|
|
261
|
+
? frame.class + "." + frame.method
|
|
262
|
+
: frame.method;
|
|
263
|
+
return {
|
|
264
|
+
method: method || '',
|
|
265
|
+
file: frame.file || '',
|
|
266
|
+
number: frame.line || ''
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
var Honeybadger = /** @class */ (function (_super) {
|
|
272
|
+
__extends(Honeybadger, _super);
|
|
273
|
+
function Honeybadger(opts) {
|
|
274
|
+
if (opts === void 0) { opts = {}; }
|
|
275
|
+
var _this = _super.call(this, mergeDefaultOpts(opts), new Transport()) || this;
|
|
276
|
+
_this.__jsHandlerInitialized = false;
|
|
277
|
+
_this.__nativeHandlerInitialized = false;
|
|
278
|
+
_this.setContext({
|
|
279
|
+
platform: {
|
|
280
|
+
os: reactNative.Platform.OS,
|
|
281
|
+
version: reactNative.Platform.Version
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
return _this;
|
|
285
|
+
}
|
|
286
|
+
Honeybadger.prototype.configure = function (opts) {
|
|
287
|
+
if (opts === void 0) { opts = {}; }
|
|
288
|
+
this.setJavascriptErrorHandler();
|
|
289
|
+
this.setNativeExceptionHandler();
|
|
290
|
+
return _super.prototype.configure.call(this, mergeDefaultOpts(opts));
|
|
291
|
+
};
|
|
292
|
+
Honeybadger.prototype.factory = function (opts) {
|
|
293
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
294
|
+
return new Honeybadger(opts);
|
|
295
|
+
};
|
|
296
|
+
Honeybadger.prototype.checkIn = function () {
|
|
297
|
+
throw new Error('Honeybadger.checkIn() is not yet supported on react-native');
|
|
298
|
+
};
|
|
299
|
+
Honeybadger.prototype.showUserFeedbackForm = function () {
|
|
300
|
+
throw new Error('Honeybadger.showUserFeedbackForm() is not yet supported on react-native');
|
|
301
|
+
};
|
|
302
|
+
Honeybadger.prototype.setJavascriptErrorHandler = function () {
|
|
303
|
+
var _this = this;
|
|
304
|
+
if (this.__jsHandlerInitialized) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
this.logger.debug('Setting up the JavaScript global error handler.');
|
|
308
|
+
this.__originalJsHandler = ErrorUtils.getGlobalHandler();
|
|
309
|
+
ErrorUtils.setGlobalHandler(function (err, isFatal) {
|
|
310
|
+
_this.logger.debug('JavaScript global error handler triggered.');
|
|
311
|
+
_this.notify(err);
|
|
312
|
+
// Allowing the default error handler to process the error after
|
|
313
|
+
// we're done with it will show the useful RN red info box in dev.
|
|
314
|
+
// However in prod it causes duplicate errors to be reported on iOS
|
|
315
|
+
// since the default handler re-throws a native error
|
|
316
|
+
if (__DEV__ && _this.__originalJsHandler) {
|
|
317
|
+
_this.logger.debug('Passing error to previous error handler.');
|
|
318
|
+
_this.__originalJsHandler(err, isFatal);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
this.__jsHandlerInitialized = true;
|
|
322
|
+
};
|
|
323
|
+
Honeybadger.prototype.setNativeExceptionHandler = function () {
|
|
324
|
+
if (this.__nativeHandlerInitialized) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
var HoneybadgerNativeModule = reactNative.NativeModules.HoneybadgerReactNative;
|
|
328
|
+
if (!HoneybadgerNativeModule) {
|
|
329
|
+
this.logger.error('The native module was not found. Please review the installation instructions.');
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
HoneybadgerNativeModule.start();
|
|
333
|
+
var nativeEventEmitter = new reactNative.NativeEventEmitter(HoneybadgerNativeModule);
|
|
334
|
+
nativeEventEmitter.addListener('native-exception-event', this.onNativeException.bind(this));
|
|
335
|
+
this.__nativeHandlerInitialized = true;
|
|
336
|
+
};
|
|
337
|
+
Honeybadger.prototype.onNativeException = function (data) {
|
|
338
|
+
switch (reactNative.Platform.OS) {
|
|
339
|
+
case 'ios':
|
|
340
|
+
this.onNativeIOSException(data);
|
|
341
|
+
break;
|
|
342
|
+
case 'android':
|
|
343
|
+
this.onNativeAndroidException(data);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
Honeybadger.prototype.onNativeIOSException = function (data) {
|
|
348
|
+
var _a = backtraceAndDetailsFromIosException(data), backtrace = _a.backtrace, backtraceDetails = _a.backtraceDetails;
|
|
349
|
+
var notice = {
|
|
350
|
+
name: "React Native iOS " + data.type,
|
|
351
|
+
message: errorMessageFromIosException(data),
|
|
352
|
+
backtrace: backtrace,
|
|
353
|
+
details: __assign({ errorDomain: data.errorDomain || '', initialHandler: data.initialHandler || '', userInfo: data.userInfo || {}, architecture: data.architecture || '' }, backtraceDetails),
|
|
354
|
+
};
|
|
355
|
+
this.notify(notice);
|
|
356
|
+
};
|
|
357
|
+
Honeybadger.prototype.onNativeAndroidException = function (data) {
|
|
358
|
+
var notice = {
|
|
359
|
+
name: "React Native Android " + data.type,
|
|
360
|
+
message: data.message || '',
|
|
361
|
+
details: {
|
|
362
|
+
errorDomain: data.errorDomain || '',
|
|
363
|
+
initialHandler: data.initialHandler || '',
|
|
364
|
+
userInfo: data.userInfo || {},
|
|
365
|
+
architecture: data.architecture || '',
|
|
366
|
+
},
|
|
367
|
+
backtrace: backtraceFromAndroidException(data)
|
|
368
|
+
};
|
|
369
|
+
this.notify(notice);
|
|
370
|
+
};
|
|
371
|
+
return Honeybadger;
|
|
372
|
+
}(core.Client));
|
|
373
|
+
function mergeDefaultOpts(opts) {
|
|
374
|
+
return __assign({ environment: __DEV__ ? 'development' : 'production' }, opts);
|
|
375
|
+
}
|
|
376
|
+
var index = new Honeybadger();
|
|
377
|
+
|
|
378
|
+
module.exports = index;
|
|
379
|
+
//# sourceMappingURL=index.js.map
|