@metamask/base-controller
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -9,2 +9,8 @@ # Changelog | ||
## [3.1.0] | ||
### Changed | ||
- Prevent event publish from throwing error ([#1475](https://github.com/MetaMask/core/pull/1475)) | ||
- The controller messenger will no longer throw when an event subscriber throws an error. Calls to `publish` (either within controllers or on a messenger instance directly) will no longer throw errors. | ||
- Errors are thrown in a timeout handler so that they can still be logged and captured. | ||
## [3.0.0] | ||
@@ -52,3 +58,4 @@ ### Changed | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/base-controller@3.0.0...HEAD | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/base-controller@3.1.0...HEAD | ||
[3.1.0]: https://github.com/MetaMask/core/compare/@metamask/base-controller@3.0.0...@metamask/base-controller@3.1.0 | ||
[3.0.0]: https://github.com/MetaMask/core/compare/@metamask/base-controller@2.0.0...@metamask/base-controller@3.0.0 | ||
@@ -55,0 +62,0 @@ [2.0.0]: https://github.com/MetaMask/core/compare/@metamask/base-controller@1.1.2...@metamask/base-controller@2.0.0 |
@@ -262,2 +262,5 @@ export declare type ActionHandler<Action, ActionType> = (...args: ExtractActionParameters<Action, ActionType>) => ExtractActionResponse<Action, ActionType>; | ||
* | ||
* Note that this method should never throw directly. Any errors from | ||
* subscribers are captured and re-thrown in a timeout handler. | ||
* | ||
* @param eventType - The event type. This is a unique identifier for this event. | ||
@@ -264,0 +267,0 @@ * @param payload - The event payload. The type of the parameters for each event handler must |
@@ -258,2 +258,5 @@ "use strict"; | ||
* | ||
* Note that this method should never throw directly. Any errors from | ||
* subscribers are captured and re-thrown in a timeout handler. | ||
* | ||
* @param eventType - The event type. This is a unique identifier for this event. | ||
@@ -268,12 +271,21 @@ * @param payload - The event payload. The type of the parameters for each event handler must | ||
for (const [handler, selector] of subscribers.entries()) { | ||
if (selector) { | ||
const previousValue = this.eventPayloadCache.get(handler); | ||
const newValue = selector(...payload); | ||
if (newValue !== previousValue) { | ||
this.eventPayloadCache.set(handler, newValue); | ||
handler(newValue, previousValue); | ||
try { | ||
if (selector) { | ||
const previousValue = this.eventPayloadCache.get(handler); | ||
const newValue = selector(...payload); | ||
if (newValue !== previousValue) { | ||
this.eventPayloadCache.set(handler, newValue); | ||
handler(newValue, previousValue); | ||
} | ||
} | ||
else { | ||
handler(...payload); | ||
} | ||
} | ||
else { | ||
handler(...payload); | ||
catch (error) { | ||
// Throw error after timeout so that it is capured as a console error | ||
// (and by Sentry) without interrupting the event publishing. | ||
setTimeout(() => { | ||
throw error; | ||
}); | ||
} | ||
@@ -280,0 +292,0 @@ } |
{ | ||
"name": "@metamask/base-controller", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Provides scaffolding for controllers as well a communication system for all controllers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119587
1290