@metamask-previews/error-reporting-service 2.2.2-preview-77daf0c7 → 3.0.0-preview-46d2c977
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 +11 -1
- package/dist/error-reporting-service.cjs +31 -13
- package/dist/error-reporting-service.cjs.map +1 -1
- package/dist/error-reporting-service.d.cts +33 -15
- package/dist/error-reporting-service.d.cts.map +1 -1
- package/dist/error-reporting-service.d.mts +33 -15
- package/dist/error-reporting-service.d.mts.map +1 -1
- package/dist/error-reporting-service.mjs +31 -13
- package/dist/error-reporting-service.mjs.map +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6462](https://github.com/MetaMask/core/pull/6462))
|
|
15
|
+
- Previously, `ErrorReportingService` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
|
|
16
|
+
- **BREAKING:** Metadata property `anonymous` renamed to `includeInDebugSnapshot` ([#6462](https://github.com/MetaMask/core/pull/6462))
|
|
17
|
+
- Bump `@metamask/base-controller` from `^8.4.2` to `^9.0.0` ([#6962](https://github.com/MetaMask/core/pull/6962))
|
|
18
|
+
|
|
10
19
|
## [2.2.2]
|
|
11
20
|
|
|
12
21
|
### Changed
|
|
@@ -45,7 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
45
54
|
|
|
46
55
|
- Initial release ([#5882](https://github.com/MetaMask/core/pull/5882))
|
|
47
56
|
|
|
48
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@
|
|
57
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@3.0.0...HEAD
|
|
58
|
+
[3.0.0]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.2.2...@metamask/error-reporting-service@3.0.0
|
|
49
59
|
[2.2.2]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.2.1...@metamask/error-reporting-service@2.2.2
|
|
50
60
|
[2.2.1]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.2.0...@metamask/error-reporting-service@2.2.1
|
|
51
61
|
[2.2.0]: https://github.com/MetaMask/core/compare/@metamask/error-reporting-service@2.1.0...@metamask/error-reporting-service@2.2.0
|
|
@@ -29,12 +29,10 @@ exports.ErrorReportingService = void 0;
|
|
|
29
29
|
*
|
|
30
30
|
* // Define the messenger type for the controller.
|
|
31
31
|
* type AllowedActions = ErrorReportingServiceCaptureExceptionAction;
|
|
32
|
-
* type ExampleControllerMessenger =
|
|
32
|
+
* type ExampleControllerMessenger = Messenger<
|
|
33
33
|
* 'ExampleController',
|
|
34
34
|
* AllowedActions,
|
|
35
35
|
* never,
|
|
36
|
-
* AllowedActions['type'],
|
|
37
|
-
* never
|
|
38
36
|
* >;
|
|
39
37
|
*
|
|
40
38
|
* // Define the controller.
|
|
@@ -46,7 +44,7 @@ exports.ErrorReportingService = void 0;
|
|
|
46
44
|
* doSomething() {
|
|
47
45
|
* // Imagine that we do something that produces an error and we want to
|
|
48
46
|
* // report the error.
|
|
49
|
-
* this.
|
|
47
|
+
* this.messenger.call(
|
|
50
48
|
* 'ErrorReportingService:captureException',
|
|
51
49
|
* new Error('Something went wrong'),
|
|
52
50
|
* );
|
|
@@ -59,23 +57,43 @@ exports.ErrorReportingService = void 0;
|
|
|
59
57
|
* import { ErrorReportingService } from '@metamask/error-reporting-service';
|
|
60
58
|
* import { ExampleController } from './example-controller';
|
|
61
59
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
60
|
+
* type RootMessenger = Messenger<
|
|
61
|
+
* 'Root',
|
|
62
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
63
|
+
* MessengerEvents<ErrorReportingServiceMessenger>
|
|
64
|
+
* >;
|
|
65
|
+
*
|
|
66
|
+
* // Create a root messenger.
|
|
67
|
+
* const rootMessenger = new Messenger();
|
|
64
68
|
*
|
|
65
69
|
* // Register handler for the `ErrorReportingService:captureException`
|
|
66
|
-
* // action in the
|
|
67
|
-
* const errorReportingServiceMessenger =
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
+
* // action in the root messenger.
|
|
71
|
+
* const errorReportingServiceMessenger = new Messenger<
|
|
72
|
+
* 'ErrorReportingService',
|
|
73
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
74
|
+
* MessengerEvents<ErrorReportingServiceMessenger>,
|
|
75
|
+
* RootMessenger
|
|
76
|
+
* >({
|
|
77
|
+
* namespace: 'ErrorReportingService',
|
|
78
|
+
* parent: rootMessenger,
|
|
70
79
|
* });
|
|
71
80
|
* const errorReportingService = new ErrorReportingService({
|
|
72
81
|
* messenger: errorReportingServiceMessenger,
|
|
73
82
|
* captureException,
|
|
74
83
|
* });
|
|
75
84
|
*
|
|
76
|
-
* const exampleControllerMessenger =
|
|
77
|
-
*
|
|
78
|
-
*
|
|
85
|
+
* const exampleControllerMessenger = new Messenger<
|
|
86
|
+
* 'ExampleController',
|
|
87
|
+
* MessengerActions<ExampleControllerMessenger>,
|
|
88
|
+
* MessengerEvents<ExampleControllerMessenger>,
|
|
89
|
+
* RootMessenger
|
|
90
|
+
* >({
|
|
91
|
+
* namespace: 'ExampleController',
|
|
92
|
+
* parent: rootMessenger,
|
|
93
|
+
* });
|
|
94
|
+
* rootMessenger.delegate({
|
|
95
|
+
* messenger: exampleControllerMessenger,
|
|
96
|
+
* actions: ['ErrorReportingService:captureException'],
|
|
79
97
|
* });
|
|
80
98
|
* const exampleController = new ExampleController({
|
|
81
99
|
* messenger: exampleControllerMessenger,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-reporting-service.cjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
2
|
/**
|
|
3
3
|
* The action which can be used to report an error.
|
|
4
4
|
*/
|
|
@@ -30,7 +30,7 @@ type AllowedEvents = never;
|
|
|
30
30
|
* The messenger restricted to actions and events that
|
|
31
31
|
* {@link ErrorReportingService} needs to access.
|
|
32
32
|
*/
|
|
33
|
-
export type ErrorReportingServiceMessenger =
|
|
33
|
+
export type ErrorReportingServiceMessenger = Messenger<'ErrorReportingService', ErrorReportingServiceActions | AllowedActions, ErrorReportingServiceEvents | AllowedEvents>;
|
|
34
34
|
/**
|
|
35
35
|
* The options that {@link ErrorReportingService} takes.
|
|
36
36
|
*/
|
|
@@ -54,12 +54,10 @@ type ErrorReportingServiceOptions = {
|
|
|
54
54
|
*
|
|
55
55
|
* // Define the messenger type for the controller.
|
|
56
56
|
* type AllowedActions = ErrorReportingServiceCaptureExceptionAction;
|
|
57
|
-
* type ExampleControllerMessenger =
|
|
57
|
+
* type ExampleControllerMessenger = Messenger<
|
|
58
58
|
* 'ExampleController',
|
|
59
59
|
* AllowedActions,
|
|
60
60
|
* never,
|
|
61
|
-
* AllowedActions['type'],
|
|
62
|
-
* never
|
|
63
61
|
* >;
|
|
64
62
|
*
|
|
65
63
|
* // Define the controller.
|
|
@@ -71,7 +69,7 @@ type ErrorReportingServiceOptions = {
|
|
|
71
69
|
* doSomething() {
|
|
72
70
|
* // Imagine that we do something that produces an error and we want to
|
|
73
71
|
* // report the error.
|
|
74
|
-
* this.
|
|
72
|
+
* this.messenger.call(
|
|
75
73
|
* 'ErrorReportingService:captureException',
|
|
76
74
|
* new Error('Something went wrong'),
|
|
77
75
|
* );
|
|
@@ -84,23 +82,43 @@ type ErrorReportingServiceOptions = {
|
|
|
84
82
|
* import { ErrorReportingService } from '@metamask/error-reporting-service';
|
|
85
83
|
* import { ExampleController } from './example-controller';
|
|
86
84
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
85
|
+
* type RootMessenger = Messenger<
|
|
86
|
+
* 'Root',
|
|
87
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
88
|
+
* MessengerEvents<ErrorReportingServiceMessenger>
|
|
89
|
+
* >;
|
|
90
|
+
*
|
|
91
|
+
* // Create a root messenger.
|
|
92
|
+
* const rootMessenger = new Messenger();
|
|
89
93
|
*
|
|
90
94
|
* // Register handler for the `ErrorReportingService:captureException`
|
|
91
|
-
* // action in the
|
|
92
|
-
* const errorReportingServiceMessenger =
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
+
* // action in the root messenger.
|
|
96
|
+
* const errorReportingServiceMessenger = new Messenger<
|
|
97
|
+
* 'ErrorReportingService',
|
|
98
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
99
|
+
* MessengerEvents<ErrorReportingServiceMessenger>,
|
|
100
|
+
* RootMessenger
|
|
101
|
+
* >({
|
|
102
|
+
* namespace: 'ErrorReportingService',
|
|
103
|
+
* parent: rootMessenger,
|
|
95
104
|
* });
|
|
96
105
|
* const errorReportingService = new ErrorReportingService({
|
|
97
106
|
* messenger: errorReportingServiceMessenger,
|
|
98
107
|
* captureException,
|
|
99
108
|
* });
|
|
100
109
|
*
|
|
101
|
-
* const exampleControllerMessenger =
|
|
102
|
-
*
|
|
103
|
-
*
|
|
110
|
+
* const exampleControllerMessenger = new Messenger<
|
|
111
|
+
* 'ExampleController',
|
|
112
|
+
* MessengerActions<ExampleControllerMessenger>,
|
|
113
|
+
* MessengerEvents<ExampleControllerMessenger>,
|
|
114
|
+
* RootMessenger
|
|
115
|
+
* >({
|
|
116
|
+
* namespace: 'ExampleController',
|
|
117
|
+
* parent: rootMessenger,
|
|
118
|
+
* });
|
|
119
|
+
* rootMessenger.delegate({
|
|
120
|
+
* messenger: exampleControllerMessenger,
|
|
121
|
+
* actions: ['ErrorReportingService:captureException'],
|
|
104
122
|
* });
|
|
105
123
|
* const exampleController = new ExampleController({
|
|
106
124
|
* messenger: exampleControllerMessenger,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-reporting-service.d.cts","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"error-reporting-service.d.cts","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD;;GAEG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GACtC,2CAA2C,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEhD;;;GAGG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,SAAS,CACpD,uBAAuB,EACvB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,CAC5C,CAAC;AAEF;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAClC,gBAAgB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IAC5D,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,qBAAa,qBAAqB;;IAChC,IAAI,EAAE,uBAAuB,CAAoC;IAEjE,KAAK,OAAQ;IAMb;;;;;;;;OAQG;gBACS,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,4BAA4B;IAUzE;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAGrC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
2
|
/**
|
|
3
3
|
* The action which can be used to report an error.
|
|
4
4
|
*/
|
|
@@ -30,7 +30,7 @@ type AllowedEvents = never;
|
|
|
30
30
|
* The messenger restricted to actions and events that
|
|
31
31
|
* {@link ErrorReportingService} needs to access.
|
|
32
32
|
*/
|
|
33
|
-
export type ErrorReportingServiceMessenger =
|
|
33
|
+
export type ErrorReportingServiceMessenger = Messenger<'ErrorReportingService', ErrorReportingServiceActions | AllowedActions, ErrorReportingServiceEvents | AllowedEvents>;
|
|
34
34
|
/**
|
|
35
35
|
* The options that {@link ErrorReportingService} takes.
|
|
36
36
|
*/
|
|
@@ -54,12 +54,10 @@ type ErrorReportingServiceOptions = {
|
|
|
54
54
|
*
|
|
55
55
|
* // Define the messenger type for the controller.
|
|
56
56
|
* type AllowedActions = ErrorReportingServiceCaptureExceptionAction;
|
|
57
|
-
* type ExampleControllerMessenger =
|
|
57
|
+
* type ExampleControllerMessenger = Messenger<
|
|
58
58
|
* 'ExampleController',
|
|
59
59
|
* AllowedActions,
|
|
60
60
|
* never,
|
|
61
|
-
* AllowedActions['type'],
|
|
62
|
-
* never
|
|
63
61
|
* >;
|
|
64
62
|
*
|
|
65
63
|
* // Define the controller.
|
|
@@ -71,7 +69,7 @@ type ErrorReportingServiceOptions = {
|
|
|
71
69
|
* doSomething() {
|
|
72
70
|
* // Imagine that we do something that produces an error and we want to
|
|
73
71
|
* // report the error.
|
|
74
|
-
* this.
|
|
72
|
+
* this.messenger.call(
|
|
75
73
|
* 'ErrorReportingService:captureException',
|
|
76
74
|
* new Error('Something went wrong'),
|
|
77
75
|
* );
|
|
@@ -84,23 +82,43 @@ type ErrorReportingServiceOptions = {
|
|
|
84
82
|
* import { ErrorReportingService } from '@metamask/error-reporting-service';
|
|
85
83
|
* import { ExampleController } from './example-controller';
|
|
86
84
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
85
|
+
* type RootMessenger = Messenger<
|
|
86
|
+
* 'Root',
|
|
87
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
88
|
+
* MessengerEvents<ErrorReportingServiceMessenger>
|
|
89
|
+
* >;
|
|
90
|
+
*
|
|
91
|
+
* // Create a root messenger.
|
|
92
|
+
* const rootMessenger = new Messenger();
|
|
89
93
|
*
|
|
90
94
|
* // Register handler for the `ErrorReportingService:captureException`
|
|
91
|
-
* // action in the
|
|
92
|
-
* const errorReportingServiceMessenger =
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
+
* // action in the root messenger.
|
|
96
|
+
* const errorReportingServiceMessenger = new Messenger<
|
|
97
|
+
* 'ErrorReportingService',
|
|
98
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
99
|
+
* MessengerEvents<ErrorReportingServiceMessenger>,
|
|
100
|
+
* RootMessenger
|
|
101
|
+
* >({
|
|
102
|
+
* namespace: 'ErrorReportingService',
|
|
103
|
+
* parent: rootMessenger,
|
|
95
104
|
* });
|
|
96
105
|
* const errorReportingService = new ErrorReportingService({
|
|
97
106
|
* messenger: errorReportingServiceMessenger,
|
|
98
107
|
* captureException,
|
|
99
108
|
* });
|
|
100
109
|
*
|
|
101
|
-
* const exampleControllerMessenger =
|
|
102
|
-
*
|
|
103
|
-
*
|
|
110
|
+
* const exampleControllerMessenger = new Messenger<
|
|
111
|
+
* 'ExampleController',
|
|
112
|
+
* MessengerActions<ExampleControllerMessenger>,
|
|
113
|
+
* MessengerEvents<ExampleControllerMessenger>,
|
|
114
|
+
* RootMessenger
|
|
115
|
+
* >({
|
|
116
|
+
* namespace: 'ExampleController',
|
|
117
|
+
* parent: rootMessenger,
|
|
118
|
+
* });
|
|
119
|
+
* rootMessenger.delegate({
|
|
120
|
+
* messenger: exampleControllerMessenger,
|
|
121
|
+
* actions: ['ErrorReportingService:captureException'],
|
|
104
122
|
* });
|
|
105
123
|
* const exampleController = new ExampleController({
|
|
106
124
|
* messenger: exampleControllerMessenger,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-reporting-service.d.mts","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"error-reporting-service.d.mts","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD;;GAEG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GACtC,2CAA2C,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEhD;;;GAGG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,SAAS,CACpD,uBAAuB,EACvB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,CAC5C,CAAC;AAEF;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAClC,gBAAgB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IAC5D,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,qBAAa,qBAAqB;;IAChC,IAAI,EAAE,uBAAuB,CAAoC;IAEjE,KAAK,OAAQ;IAMb;;;;;;;;OAQG;gBACS,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,4BAA4B;IAUzE;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAGrC"}
|
|
@@ -26,12 +26,10 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
|
|
|
26
26
|
*
|
|
27
27
|
* // Define the messenger type for the controller.
|
|
28
28
|
* type AllowedActions = ErrorReportingServiceCaptureExceptionAction;
|
|
29
|
-
* type ExampleControllerMessenger =
|
|
29
|
+
* type ExampleControllerMessenger = Messenger<
|
|
30
30
|
* 'ExampleController',
|
|
31
31
|
* AllowedActions,
|
|
32
32
|
* never,
|
|
33
|
-
* AllowedActions['type'],
|
|
34
|
-
* never
|
|
35
33
|
* >;
|
|
36
34
|
*
|
|
37
35
|
* // Define the controller.
|
|
@@ -43,7 +41,7 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
|
|
|
43
41
|
* doSomething() {
|
|
44
42
|
* // Imagine that we do something that produces an error and we want to
|
|
45
43
|
* // report the error.
|
|
46
|
-
* this.
|
|
44
|
+
* this.messenger.call(
|
|
47
45
|
* 'ErrorReportingService:captureException',
|
|
48
46
|
* new Error('Something went wrong'),
|
|
49
47
|
* );
|
|
@@ -56,23 +54,43 @@ var _ErrorReportingService_captureException, _ErrorReportingService_messenger;
|
|
|
56
54
|
* import { ErrorReportingService } from '@metamask/error-reporting-service';
|
|
57
55
|
* import { ExampleController } from './example-controller';
|
|
58
56
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
57
|
+
* type RootMessenger = Messenger<
|
|
58
|
+
* 'Root',
|
|
59
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
60
|
+
* MessengerEvents<ErrorReportingServiceMessenger>
|
|
61
|
+
* >;
|
|
62
|
+
*
|
|
63
|
+
* // Create a root messenger.
|
|
64
|
+
* const rootMessenger = new Messenger();
|
|
61
65
|
*
|
|
62
66
|
* // Register handler for the `ErrorReportingService:captureException`
|
|
63
|
-
* // action in the
|
|
64
|
-
* const errorReportingServiceMessenger =
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
+
* // action in the root messenger.
|
|
68
|
+
* const errorReportingServiceMessenger = new Messenger<
|
|
69
|
+
* 'ErrorReportingService',
|
|
70
|
+
* MessengerActions<ErrorReportingServiceMessenger>,
|
|
71
|
+
* MessengerEvents<ErrorReportingServiceMessenger>,
|
|
72
|
+
* RootMessenger
|
|
73
|
+
* >({
|
|
74
|
+
* namespace: 'ErrorReportingService',
|
|
75
|
+
* parent: rootMessenger,
|
|
67
76
|
* });
|
|
68
77
|
* const errorReportingService = new ErrorReportingService({
|
|
69
78
|
* messenger: errorReportingServiceMessenger,
|
|
70
79
|
* captureException,
|
|
71
80
|
* });
|
|
72
81
|
*
|
|
73
|
-
* const exampleControllerMessenger =
|
|
74
|
-
*
|
|
75
|
-
*
|
|
82
|
+
* const exampleControllerMessenger = new Messenger<
|
|
83
|
+
* 'ExampleController',
|
|
84
|
+
* MessengerActions<ExampleControllerMessenger>,
|
|
85
|
+
* MessengerEvents<ExampleControllerMessenger>,
|
|
86
|
+
* RootMessenger
|
|
87
|
+
* >({
|
|
88
|
+
* namespace: 'ExampleController',
|
|
89
|
+
* parent: rootMessenger,
|
|
90
|
+
* });
|
|
91
|
+
* rootMessenger.delegate({
|
|
92
|
+
* messenger: exampleControllerMessenger,
|
|
93
|
+
* actions: ['ErrorReportingService:captureException'],
|
|
76
94
|
* });
|
|
77
95
|
* const exampleController = new ExampleController({
|
|
78
96
|
* messenger: exampleControllerMessenger,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-reporting-service.mjs","sourceRoot":"","sources":["../src/error-reporting-service.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/error-reporting-service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-preview-46d2c977",
|
|
4
4
|
"description": "Logs errors to an error reporting service such as Sentry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"since-latest-release": "../../scripts/since-latest-release.sh"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@metamask/base-controller": "^
|
|
50
|
+
"@metamask/base-controller": "^9.0.0",
|
|
51
|
+
"@metamask/messenger": "^0.3.0"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@metamask/auto-changelog": "^3.4.4",
|