@metamask-previews/error-reporting-service 2.2.1-preview-ab0ad568 → 2.2.2-preview-0458fe94
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 +10 -3
- package/dist/error-reporting-service.cjs +11 -11
- package/dist/error-reporting-service.cjs.map +1 -1
- package/dist/error-reporting-service.d.cts +11 -11
- package/dist/error-reporting-service.d.mts +11 -11
- package/dist/error-reporting-service.mjs +11 -11
- package/dist/error-reporting-service.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6462](https://github.com/MetaMask/core/pull/6462))
|
|
13
|
+
- Previously, `ErrorReportingService` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
|
|
14
|
+
- **BREAKING:** Metadata property `anonymous` renamed to `includeInDebugSnapshot` ([#6462](https://github.com/MetaMask/core/pull/6462))
|
|
15
|
+
|
|
16
|
+
## [2.2.2]
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
12
20
|
- Bump `@metamask/base-controller` from `^8.4.1` to `^8.4.2` ([#6917](https://github.com/MetaMask/core/pull/6917))
|
|
13
21
|
|
|
14
22
|
## [2.2.1]
|
|
@@ -27,8 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
27
35
|
|
|
28
36
|
### Changed
|
|
29
37
|
|
|
30
|
-
- **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6462](https://github.com/MetaMask/core/pull/6462))
|
|
31
|
-
- Previously, `ErrorReportingService` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
|
|
32
38
|
- Bump `@metamask/base-controller` from `^8.0.1` to `^8.4.0` ([#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465), [#6632](https://github.com/MetaMask/core/pull/6632))
|
|
33
39
|
|
|
34
40
|
## [2.0.0]
|
|
@@ -45,7 +51,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
45
51
|
|
|
46
52
|
- Initial release ([#5882](https://github.com/MetaMask/core/pull/5882))
|
|
47
53
|
|
|
48
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.2.
|
|
54
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.2.2...HEAD
|
|
55
|
+
[2.2.2]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.2.1...@metamask/error-reporting-service@2.2.2
|
|
49
56
|
[2.2.1]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.2.0...@metamask/error-reporting-service@2.2.1
|
|
50
57
|
[2.2.0]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.1.0...@metamask/error-reporting-service@2.2.0
|
|
51
58
|
[2.1.0]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.0.0...@metamask/error-reporting-service@2.1.0
|
|
@@ -57,17 +57,17 @@ exports.ErrorReportingService = void 0;
|
|
|
57
57
|
* import { ErrorReportingService } from '@metamask/error-reporting-service';
|
|
58
58
|
* import { ExampleController } from './example-controller';
|
|
59
59
|
*
|
|
60
|
-
* type
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
60
|
+
* type RootMessenger = Messenger<
|
|
61
|
+
* 'Root',
|
|
62
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
63
|
+
* MessengerEvents<ErrorReportingServiceMessenger>
|
|
64
|
+
* >;
|
|
65
65
|
*
|
|
66
|
-
* // Create a
|
|
67
|
-
* const
|
|
66
|
+
* // Create a root messenger.
|
|
67
|
+
* const rootMessenger = new Messenger();
|
|
68
68
|
*
|
|
69
69
|
* // Register handler for the `ErrorReportingService:captureException`
|
|
70
|
-
* // action in the
|
|
70
|
+
* // action in the root messenger.
|
|
71
71
|
* const errorReportingServiceMessenger = new Messenger<
|
|
72
72
|
* 'ErrorReportingService',
|
|
73
73
|
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
@@ -75,7 +75,7 @@ exports.ErrorReportingService = void 0;
|
|
|
75
75
|
* RootMessenger
|
|
76
76
|
* >({
|
|
77
77
|
* namespace: 'ErrorReportingService',
|
|
78
|
-
* parent:
|
|
78
|
+
* parent: rootMessenger,
|
|
79
79
|
* });
|
|
80
80
|
* const errorReportingService = new ErrorReportingService({
|
|
81
81
|
* messenger: errorReportingServiceMessenger,
|
|
@@ -89,9 +89,9 @@ exports.ErrorReportingService = void 0;
|
|
|
89
89
|
* RootMessenger
|
|
90
90
|
* >({
|
|
91
91
|
* namespace: 'ExampleController',
|
|
92
|
-
* parent:
|
|
92
|
+
* parent: rootMessenger,
|
|
93
93
|
* });
|
|
94
|
-
*
|
|
94
|
+
* rootMessenger.delegate({
|
|
95
95
|
* messenger: exampleControllerMessenger,
|
|
96
96
|
* actions: ['ErrorReportingService:captureException'],
|
|
97
97
|
* });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-reporting-service.cjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAqDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,MAAa,qBAAqB;IAShC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAjBzE,SAAI,GAA4B,uBAAgC,CAAC;QAEjE,UAAK,GAAG,IAAI,CAAC;QAEJ,0DAAoE;QAEpE,mDAA2C;QAYlD,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2CAAqB,gBAAgB,MAAA,CAAC;QAE1C,uBAAA,IAAI,wCAAW,CAAC,qBAAqB,CACnC,wCAAwC,EACxC,uBAAA,IAAI,+CAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAY;QAC3B,uBAAA,IAAI,+CAAkB,MAAtB,IAAI,EAAmB,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AApCD,sDAoCC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\n/**\n * The action which can be used to report an error.\n */\nexport type ErrorReportingServiceCaptureExceptionAction = {\n type: 'ErrorReportingService:captureException';\n handler: ErrorReportingService['captureException'];\n};\n\n/**\n * All actions that {@link ErrorReportingService} registers so that other\n * modules can call them.\n */\nexport type ErrorReportingServiceActions =\n ErrorReportingServiceCaptureExceptionAction;\n\n/**\n * All events that {@link ErrorReportingService} publishes so that other modules\n * can subscribe to them.\n */\nexport type ErrorReportingServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link ErrorReportingService}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * All events published by other modules that {@link ErrorReportingService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link ErrorReportingService} needs to access.\n */\nexport type ErrorReportingServiceMessenger = Messenger<\n 'ErrorReportingService',\n ErrorReportingServiceActions | AllowedActions,\n ErrorReportingServiceEvents | AllowedEvents\n>;\n\n/**\n * The options that {@link ErrorReportingService} takes.\n */\ntype ErrorReportingServiceOptions = {\n captureException: ErrorReportingService['captureException'];\n messenger: ErrorReportingServiceMessenger;\n};\n\n/**\n * `ErrorReportingService` is designed to log an error to an error reporting app\n * such as Sentry, but in an agnostic fashion.\n *\n * @example\n *\n * In this example, we have a controller, and something bad happens, but we want\n * to report an error instead of throwing it.\n *\n * ``` ts\n * // === Controller file ===\n *\n * import type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\n *\n * // Define the messenger type for the controller.\n * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n * type ExampleControllerMessenger = Messenger<\n * 'ExampleController',\n * AllowedActions,\n * never,\n * >;\n *\n * // Define the controller.\n * class ExampleController extends BaseController<\n * 'ExampleController',\n * ExampleControllerState,\n * ExampleControllerMessenger\n * > {\n * doSomething() {\n * // Imagine that we do something that produces an error and we want to\n * // report the error.\n * this.messenger.call(\n * 'ErrorReportingService:captureException',\n * new Error('Something went wrong'),\n * );\n * }\n * }\n *\n * // === Initialization file ===\n *\n * import { captureException } from '@sentry/browser';\n * import { ErrorReportingService } from '@metamask/error-reporting-service';\n * import { ExampleController } from './example-controller';\n *\n * type
|
|
1
|
+
{"version":3,"file":"error-reporting-service.cjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAqDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,MAAa,qBAAqB;IAShC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAjBzE,SAAI,GAA4B,uBAAgC,CAAC;QAEjE,UAAK,GAAG,IAAI,CAAC;QAEJ,0DAAoE;QAEpE,mDAA2C;QAYlD,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2CAAqB,gBAAgB,MAAA,CAAC;QAE1C,uBAAA,IAAI,wCAAW,CAAC,qBAAqB,CACnC,wCAAwC,EACxC,uBAAA,IAAI,+CAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAY;QAC3B,uBAAA,IAAI,+CAAkB,MAAtB,IAAI,EAAmB,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AApCD,sDAoCC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\n/**\n * The action which can be used to report an error.\n */\nexport type ErrorReportingServiceCaptureExceptionAction = {\n type: 'ErrorReportingService:captureException';\n handler: ErrorReportingService['captureException'];\n};\n\n/**\n * All actions that {@link ErrorReportingService} registers so that other\n * modules can call them.\n */\nexport type ErrorReportingServiceActions =\n ErrorReportingServiceCaptureExceptionAction;\n\n/**\n * All events that {@link ErrorReportingService} publishes so that other modules\n * can subscribe to them.\n */\nexport type ErrorReportingServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link ErrorReportingService}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * All events published by other modules that {@link ErrorReportingService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link ErrorReportingService} needs to access.\n */\nexport type ErrorReportingServiceMessenger = Messenger<\n 'ErrorReportingService',\n ErrorReportingServiceActions | AllowedActions,\n ErrorReportingServiceEvents | AllowedEvents\n>;\n\n/**\n * The options that {@link ErrorReportingService} takes.\n */\ntype ErrorReportingServiceOptions = {\n captureException: ErrorReportingService['captureException'];\n messenger: ErrorReportingServiceMessenger;\n};\n\n/**\n * `ErrorReportingService` is designed to log an error to an error reporting app\n * such as Sentry, but in an agnostic fashion.\n *\n * @example\n *\n * In this example, we have a controller, and something bad happens, but we want\n * to report an error instead of throwing it.\n *\n * ``` ts\n * // === Controller file ===\n *\n * import type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\n *\n * // Define the messenger type for the controller.\n * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n * type ExampleControllerMessenger = Messenger<\n * 'ExampleController',\n * AllowedActions,\n * never,\n * >;\n *\n * // Define the controller.\n * class ExampleController extends BaseController<\n * 'ExampleController',\n * ExampleControllerState,\n * ExampleControllerMessenger\n * > {\n * doSomething() {\n * // Imagine that we do something that produces an error and we want to\n * // report the error.\n * this.messenger.call(\n * 'ErrorReportingService:captureException',\n * new Error('Something went wrong'),\n * );\n * }\n * }\n *\n * // === Initialization file ===\n *\n * import { captureException } from '@sentry/browser';\n * import { ErrorReportingService } from '@metamask/error-reporting-service';\n * import { ExampleController } from './example-controller';\n *\n * type RootMessenger = Messenger<\n * 'Root',\n * MessengerActions<ErrorReportingServiceMessenger>,\n * MessengerEvents<ErrorReportingServiceMessenger>\n * >;\n *\n * // Create a root messenger.\n * const rootMessenger = new Messenger();\n *\n * // Register handler for the `ErrorReportingService:captureException`\n * // action in the root messenger.\n * const errorReportingServiceMessenger = new Messenger<\n * 'ErrorReportingService',\n * MessengerActions<ErrorReportingServiceMessenger>,\n * MessengerEvents<ErrorReportingServiceMessenger>,\n * RootMessenger\n * >({\n * namespace: 'ErrorReportingService',\n * parent: rootMessenger,\n * });\n * const errorReportingService = new ErrorReportingService({\n * messenger: errorReportingServiceMessenger,\n * captureException,\n * });\n *\n * const exampleControllerMessenger = new Messenger<\n * 'ExampleController',\n * MessengerActions<ExampleControllerMessenger>,\n * MessengerEvents<ExampleControllerMessenger>,\n * RootMessenger\n * >({\n * namespace: 'ExampleController',\n * parent: rootMessenger,\n * });\n * rootMessenger.delegate({\n * messenger: exampleControllerMessenger,\n * actions: ['ErrorReportingService:captureException'],\n * });\n * const exampleController = new ExampleController({\n * messenger: exampleControllerMessenger,\n * });\n *\n * // === Somewhere else ===\n *\n * // Now this will report an error without throwing it.\n * exampleController.doSomething();\n * ```\n */\nexport class ErrorReportingService {\n name: 'ErrorReportingService' = 'ErrorReportingService' as const;\n\n state = null;\n\n readonly #captureException: ErrorReportingServiceOptions['captureException'];\n\n readonly #messenger: ErrorReportingServiceMessenger;\n\n /**\n * Constructs a new ErrorReportingService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * ErrorReportingService.\n * @param options.captureException - A function that stores the given error in\n * the error reporting service.\n */\n constructor({ messenger, captureException }: ErrorReportingServiceOptions) {\n this.#messenger = messenger;\n this.#captureException = captureException;\n\n this.#messenger.registerActionHandler(\n 'ErrorReportingService:captureException',\n this.#captureException.bind(this),\n );\n }\n\n /**\n * Reports the given error to an external location.\n *\n * @param error - The error to report.\n */\n captureException(error: Error): void {\n this.#captureException(error);\n }\n}\n"]}
|
|
@@ -82,17 +82,17 @@ type ErrorReportingServiceOptions = {
|
|
|
82
82
|
* import { ErrorReportingService } from '@metamask/error-reporting-service';
|
|
83
83
|
* import { ExampleController } from './example-controller';
|
|
84
84
|
*
|
|
85
|
-
* type
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
85
|
+
* type RootMessenger = Messenger<
|
|
86
|
+
* 'Root',
|
|
87
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
88
|
+
* MessengerEvents<ErrorReportingServiceMessenger>
|
|
89
|
+
* >;
|
|
90
90
|
*
|
|
91
|
-
* // Create a
|
|
92
|
-
* const
|
|
91
|
+
* // Create a root messenger.
|
|
92
|
+
* const rootMessenger = new Messenger();
|
|
93
93
|
*
|
|
94
94
|
* // Register handler for the `ErrorReportingService:captureException`
|
|
95
|
-
* // action in the
|
|
95
|
+
* // action in the root messenger.
|
|
96
96
|
* const errorReportingServiceMessenger = new Messenger<
|
|
97
97
|
* 'ErrorReportingService',
|
|
98
98
|
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
@@ -100,7 +100,7 @@ type ErrorReportingServiceOptions = {
|
|
|
100
100
|
* RootMessenger
|
|
101
101
|
* >({
|
|
102
102
|
* namespace: 'ErrorReportingService',
|
|
103
|
-
* parent:
|
|
103
|
+
* parent: rootMessenger,
|
|
104
104
|
* });
|
|
105
105
|
* const errorReportingService = new ErrorReportingService({
|
|
106
106
|
* messenger: errorReportingServiceMessenger,
|
|
@@ -114,9 +114,9 @@ type ErrorReportingServiceOptions = {
|
|
|
114
114
|
* RootMessenger
|
|
115
115
|
* >({
|
|
116
116
|
* namespace: 'ExampleController',
|
|
117
|
-
* parent:
|
|
117
|
+
* parent: rootMessenger,
|
|
118
118
|
* });
|
|
119
|
-
*
|
|
119
|
+
* rootMessenger.delegate({
|
|
120
120
|
* messenger: exampleControllerMessenger,
|
|
121
121
|
* actions: ['ErrorReportingService:captureException'],
|
|
122
122
|
* });
|
|
@@ -82,17 +82,17 @@ type ErrorReportingServiceOptions = {
|
|
|
82
82
|
* import { ErrorReportingService } from '@metamask/error-reporting-service';
|
|
83
83
|
* import { ExampleController } from './example-controller';
|
|
84
84
|
*
|
|
85
|
-
* type
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
85
|
+
* type RootMessenger = Messenger<
|
|
86
|
+
* 'Root',
|
|
87
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
88
|
+
* MessengerEvents<ErrorReportingServiceMessenger>
|
|
89
|
+
* >;
|
|
90
90
|
*
|
|
91
|
-
* // Create a
|
|
92
|
-
* const
|
|
91
|
+
* // Create a root messenger.
|
|
92
|
+
* const rootMessenger = new Messenger();
|
|
93
93
|
*
|
|
94
94
|
* // Register handler for the `ErrorReportingService:captureException`
|
|
95
|
-
* // action in the
|
|
95
|
+
* // action in the root messenger.
|
|
96
96
|
* const errorReportingServiceMessenger = new Messenger<
|
|
97
97
|
* 'ErrorReportingService',
|
|
98
98
|
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
@@ -100,7 +100,7 @@ type ErrorReportingServiceOptions = {
|
|
|
100
100
|
* RootMessenger
|
|
101
101
|
* >({
|
|
102
102
|
* namespace: 'ErrorReportingService',
|
|
103
|
-
* parent:
|
|
103
|
+
* parent: rootMessenger,
|
|
104
104
|
* });
|
|
105
105
|
* const errorReportingService = new ErrorReportingService({
|
|
106
106
|
* messenger: errorReportingServiceMessenger,
|
|
@@ -114,9 +114,9 @@ type ErrorReportingServiceOptions = {
|
|
|
114
114
|
* RootMessenger
|
|
115
115
|
* >({
|
|
116
116
|
* namespace: 'ExampleController',
|
|
117
|
-
* parent:
|
|
117
|
+
* parent: rootMessenger,
|
|
118
118
|
* });
|
|
119
|
-
*
|
|
119
|
+
* rootMessenger.delegate({
|
|
120
120
|
* messenger: exampleControllerMessenger,
|
|
121
121
|
* actions: ['ErrorReportingService:captureException'],
|
|
122
122
|
* });
|
|
@@ -54,17 +54,17 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
|
|
|
54
54
|
* import { ErrorReportingService } from '@metamask/error-reporting-service';
|
|
55
55
|
* import { ExampleController } from './example-controller';
|
|
56
56
|
*
|
|
57
|
-
* type
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
57
|
+
* type RootMessenger = Messenger<
|
|
58
|
+
* 'Root',
|
|
59
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
60
|
+
* MessengerEvents<ErrorReportingServiceMessenger>
|
|
61
|
+
* >;
|
|
62
62
|
*
|
|
63
|
-
* // Create a
|
|
64
|
-
* const
|
|
63
|
+
* // Create a root messenger.
|
|
64
|
+
* const rootMessenger = new Messenger();
|
|
65
65
|
*
|
|
66
66
|
* // Register handler for the `ErrorReportingService:captureException`
|
|
67
|
-
* // action in the
|
|
67
|
+
* // action in the root messenger.
|
|
68
68
|
* const errorReportingServiceMessenger = new Messenger<
|
|
69
69
|
* 'ErrorReportingService',
|
|
70
70
|
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
@@ -72,7 +72,7 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
|
|
|
72
72
|
* RootMessenger
|
|
73
73
|
* >({
|
|
74
74
|
* namespace: 'ErrorReportingService',
|
|
75
|
-
* parent:
|
|
75
|
+
* parent: rootMessenger,
|
|
76
76
|
* });
|
|
77
77
|
* const errorReportingService = new ErrorReportingService({
|
|
78
78
|
* messenger: errorReportingServiceMessenger,
|
|
@@ -86,9 +86,9 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
|
|
|
86
86
|
* RootMessenger
|
|
87
87
|
* >({
|
|
88
88
|
* namespace: 'ExampleController',
|
|
89
|
-
* parent:
|
|
89
|
+
* parent: rootMessenger,
|
|
90
90
|
* });
|
|
91
|
-
*
|
|
91
|
+
* rootMessenger.delegate({
|
|
92
92
|
* messenger: exampleControllerMessenger,
|
|
93
93
|
* actions: ['ErrorReportingService:captureException'],
|
|
94
94
|
* });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-reporting-service.mjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAqDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,MAAM,OAAO,qBAAqB;IAShC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAjBzE,SAAI,GAA4B,uBAAgC,CAAC;QAEjE,UAAK,GAAG,IAAI,CAAC;QAEJ,0DAAoE;QAEpE,mDAA2C;QAYlD,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2CAAqB,gBAAgB,MAAA,CAAC;QAE1C,uBAAA,IAAI,wCAAW,CAAC,qBAAqB,CACnC,wCAAwC,EACxC,uBAAA,IAAI,+CAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAY;QAC3B,uBAAA,IAAI,+CAAkB,MAAtB,IAAI,EAAmB,KAAK,CAAC,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\n/**\n * The action which can be used to report an error.\n */\nexport type ErrorReportingServiceCaptureExceptionAction = {\n type: 'ErrorReportingService:captureException';\n handler: ErrorReportingService['captureException'];\n};\n\n/**\n * All actions that {@link ErrorReportingService} registers so that other\n * modules can call them.\n */\nexport type ErrorReportingServiceActions =\n ErrorReportingServiceCaptureExceptionAction;\n\n/**\n * All events that {@link ErrorReportingService} publishes so that other modules\n * can subscribe to them.\n */\nexport type ErrorReportingServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link ErrorReportingService}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * All events published by other modules that {@link ErrorReportingService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link ErrorReportingService} needs to access.\n */\nexport type ErrorReportingServiceMessenger = Messenger<\n 'ErrorReportingService',\n ErrorReportingServiceActions | AllowedActions,\n ErrorReportingServiceEvents | AllowedEvents\n>;\n\n/**\n * The options that {@link ErrorReportingService} takes.\n */\ntype ErrorReportingServiceOptions = {\n captureException: ErrorReportingService['captureException'];\n messenger: ErrorReportingServiceMessenger;\n};\n\n/**\n * `ErrorReportingService` is designed to log an error to an error reporting app\n * such as Sentry, but in an agnostic fashion.\n *\n * @example\n *\n * In this example, we have a controller, and something bad happens, but we want\n * to report an error instead of throwing it.\n *\n * ``` ts\n * // === Controller file ===\n *\n * import type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\n *\n * // Define the messenger type for the controller.\n * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n * type ExampleControllerMessenger = Messenger<\n * 'ExampleController',\n * AllowedActions,\n * never,\n * >;\n *\n * // Define the controller.\n * class ExampleController extends BaseController<\n * 'ExampleController',\n * ExampleControllerState,\n * ExampleControllerMessenger\n * > {\n * doSomething() {\n * // Imagine that we do something that produces an error and we want to\n * // report the error.\n * this.messenger.call(\n * 'ErrorReportingService:captureException',\n * new Error('Something went wrong'),\n * );\n * }\n * }\n *\n * // === Initialization file ===\n *\n * import { captureException } from '@sentry/browser';\n * import { ErrorReportingService } from '@metamask/error-reporting-service';\n * import { ExampleController } from './example-controller';\n *\n * type
|
|
1
|
+
{"version":3,"file":"error-reporting-service.mjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAqDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,MAAM,OAAO,qBAAqB;IAShC;;;;;;;;OAQG;IACH,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAgC;QAjBzE,SAAI,GAA4B,uBAAgC,CAAC;QAEjE,UAAK,GAAG,IAAI,CAAC;QAEJ,0DAAoE;QAEpE,mDAA2C;QAYlD,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2CAAqB,gBAAgB,MAAA,CAAC;QAE1C,uBAAA,IAAI,wCAAW,CAAC,qBAAqB,CACnC,wCAAwC,EACxC,uBAAA,IAAI,+CAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAY;QAC3B,uBAAA,IAAI,+CAAkB,MAAtB,IAAI,EAAmB,KAAK,CAAC,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\n/**\n * The action which can be used to report an error.\n */\nexport type ErrorReportingServiceCaptureExceptionAction = {\n type: 'ErrorReportingService:captureException';\n handler: ErrorReportingService['captureException'];\n};\n\n/**\n * All actions that {@link ErrorReportingService} registers so that other\n * modules can call them.\n */\nexport type ErrorReportingServiceActions =\n ErrorReportingServiceCaptureExceptionAction;\n\n/**\n * All events that {@link ErrorReportingService} publishes so that other modules\n * can subscribe to them.\n */\nexport type ErrorReportingServiceEvents = never;\n\n/**\n * All actions registered by other modules that {@link ErrorReportingService}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * All events published by other modules that {@link ErrorReportingService}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events that\n * {@link ErrorReportingService} needs to access.\n */\nexport type ErrorReportingServiceMessenger = Messenger<\n 'ErrorReportingService',\n ErrorReportingServiceActions | AllowedActions,\n ErrorReportingServiceEvents | AllowedEvents\n>;\n\n/**\n * The options that {@link ErrorReportingService} takes.\n */\ntype ErrorReportingServiceOptions = {\n captureException: ErrorReportingService['captureException'];\n messenger: ErrorReportingServiceMessenger;\n};\n\n/**\n * `ErrorReportingService` is designed to log an error to an error reporting app\n * such as Sentry, but in an agnostic fashion.\n *\n * @example\n *\n * In this example, we have a controller, and something bad happens, but we want\n * to report an error instead of throwing it.\n *\n * ``` ts\n * // === Controller file ===\n *\n * import type { ErrorReportingServiceCaptureExceptionAction } from '@metamask/error-reporting-service';\n *\n * // Define the messenger type for the controller.\n * type AllowedActions = ErrorReportingServiceCaptureExceptionAction;\n * type ExampleControllerMessenger = Messenger<\n * 'ExampleController',\n * AllowedActions,\n * never,\n * >;\n *\n * // Define the controller.\n * class ExampleController extends BaseController<\n * 'ExampleController',\n * ExampleControllerState,\n * ExampleControllerMessenger\n * > {\n * doSomething() {\n * // Imagine that we do something that produces an error and we want to\n * // report the error.\n * this.messenger.call(\n * 'ErrorReportingService:captureException',\n * new Error('Something went wrong'),\n * );\n * }\n * }\n *\n * // === Initialization file ===\n *\n * import { captureException } from '@sentry/browser';\n * import { ErrorReportingService } from '@metamask/error-reporting-service';\n * import { ExampleController } from './example-controller';\n *\n * type RootMessenger = Messenger<\n * 'Root',\n * MessengerActions<ErrorReportingServiceMessenger>,\n * MessengerEvents<ErrorReportingServiceMessenger>\n * >;\n *\n * // Create a root messenger.\n * const rootMessenger = new Messenger();\n *\n * // Register handler for the `ErrorReportingService:captureException`\n * // action in the root messenger.\n * const errorReportingServiceMessenger = new Messenger<\n * 'ErrorReportingService',\n * MessengerActions<ErrorReportingServiceMessenger>,\n * MessengerEvents<ErrorReportingServiceMessenger>,\n * RootMessenger\n * >({\n * namespace: 'ErrorReportingService',\n * parent: rootMessenger,\n * });\n * const errorReportingService = new ErrorReportingService({\n * messenger: errorReportingServiceMessenger,\n * captureException,\n * });\n *\n * const exampleControllerMessenger = new Messenger<\n * 'ExampleController',\n * MessengerActions<ExampleControllerMessenger>,\n * MessengerEvents<ExampleControllerMessenger>,\n * RootMessenger\n * >({\n * namespace: 'ExampleController',\n * parent: rootMessenger,\n * });\n * rootMessenger.delegate({\n * messenger: exampleControllerMessenger,\n * actions: ['ErrorReportingService:captureException'],\n * });\n * const exampleController = new ExampleController({\n * messenger: exampleControllerMessenger,\n * });\n *\n * // === Somewhere else ===\n *\n * // Now this will report an error without throwing it.\n * exampleController.doSomething();\n * ```\n */\nexport class ErrorReportingService {\n name: 'ErrorReportingService' = 'ErrorReportingService' as const;\n\n state = null;\n\n readonly #captureException: ErrorReportingServiceOptions['captureException'];\n\n readonly #messenger: ErrorReportingServiceMessenger;\n\n /**\n * Constructs a new ErrorReportingService.\n *\n * @param options - The options.\n * @param options.messenger - The messenger suited to this\n * ErrorReportingService.\n * @param options.captureException - A function that stores the given error in\n * the error reporting service.\n */\n constructor({ messenger, captureException }: ErrorReportingServiceOptions) {\n this.#messenger = messenger;\n this.#captureException = captureException;\n\n this.#messenger.registerActionHandler(\n 'ErrorReportingService:captureException',\n this.#captureException.bind(this),\n );\n }\n\n /**\n * Reports the given error to an external location.\n *\n * @param error - The error to report.\n */\n captureException(error: Error): void {\n this.#captureException(error);\n }\n}\n"]}
|
package/package.json
CHANGED