fix: handle update position tpsl error handling, dedupe flipPosition trace#29817
Conversation
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Risk: Low — these are error logging/observability changes only. No functional behavior changes to trading operations, no UI rendering changes, no shared component modifications. Tag selection rationale:
No other tags are warranted as the changes are isolated to Perps functionality with no impact on accounts, identity, network, browser, snaps, swaps, or other features. Performance Test Selection: |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6230410. Configure here.
| } catch (error) { | ||
| errorMessage = error instanceof Error ? error.message : 'Unknown error'; | ||
| traceData = { success: false, error: errorMessage }; | ||
|
|
There was a problem hiding this comment.
Missing logger.error for non-throwing TPSL provider failures
Medium Severity
The PR adds logger.error to the else branch (non-throwing provider failure) of cancelOrder and closePosition, but omits the same treatment for updatePositionTPSL. When the TPSL provider returns {success: false} without throwing, the else block at line 1783 sets traceData but never calls this.#deps.logger.error, so the failure is silently swallowed in Sentry. This contradicts the PR's stated goal of making Sentry monitoring consistent across all trading write paths.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 6230410. Configure here.
|
Automated Review — PR #29817
SummaryThis PR closes three Sentry observability gaps in the Perps TradingService:
All three claims are verified by code review and unit tests. The changes achieve their stated goal. Full review detailsRecipe CoverageSkipped (standard-tier,
Overall recipe coverage: 0/3 ACs PROVEN (all verified via code review + tests) Prior Reviews
No human reviews yet. Acceptance Criteria Validation
Code Quality
Fix Quality
Live Validation
Correctness
Static Analysis
Architecture & Domain
Risk Assessment
Recommended Action[APPROVE] Minor suggestions:
Line comments (3 comments: 2 suggestion, 1 nitpick)
|
abretonc7s
left a comment
There was a problem hiding this comment.
Automated review — see comment above for full details.
| }, | ||
| ); | ||
|
|
||
| this.#deps.logger.error( |
There was a problem hiding this comment.
suggestion — The new #getErrorContext calls produce a flat {controller, method, ...} object, while the existing catch block at line 1491 uses the verbose {tags: {...}, context: {name, data: {...}}} format. This means Sentry events for the same method will have different context shapes depending on throw vs non-throwing failure. Consider aligning both paths in a follow-up so Sentry dashboards can query consistently.





Description
Fixes two Perps error-reporting gaps to make Sentry monitoring consistent across all trading write paths in TradingService:
updatePositionTPSL was silently missing controller-level logging. When a TP/SL update threw, the controller's catch block set traceData and rethrew but never called this.#deps.logger.error. Every other write method in TradingService (cancelOrder, cancelOrders, closePositions, updateMargin) calls logger.error in its catch. This gap is now closed.
flipPosition errors were double-reported to Sentry. The controller already calls this.#deps.logger.error (which routes to Sentry.captureException) when flipPosition throws. The UI hook usePerpsFlipPosition was catching the rethrown error and calling Logger.error again — sending the same event to Sentry twice. The redundant Logger.error call has been removed from the hook; the controller remains the single source of truth. User-facing feedback (error toast and onError callback) is preserved.
Fixed Perps trading errors (position close, order cancel) being silently swallowed when the provider reports failure — they now appear in Sentry with the underlying cause message
This will need to be synced with core to include changes to TradingService in order to propagate to extension
Changelog
CHANGELOG entry: Fixed missing controller-level Sentry reporting for TP/SL update failures in the Perps trading service
CHANGELOG entry: Fixed duplicate Sentry reports when a
flipPositioncall throwsFixed missing Sentry logging when trading operations return a failure result without throwing:
closePosition,cancelOrder,closePositions, andcancelOrdersnow calllogger.errorat the controller levelRelated issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Medium Risk
Touches Perps trading write paths to change when/where errors are logged and surfaced; low functional risk but could impact Sentry noise and observability if context or failure conditions are incorrect.
Overview
Improves Perps error reporting consistency by moving/adding controller-level
logger.errorcalls when providers return failure results (not just when they throw), including singlecancelOrder/closePositionfailures and batchcancelOrders/closePositionspartial/full failures.Adds missing exception logging for
updatePositionTPSLso thrown errors are captured with method/symbol context.Removes
Logger.errorSentry reporting from the UIusePerpsFlipPositionhook to avoid double-reporting exceptions (toast +onErrorbehavior remains), and updates tests to assert the deduped behavior and the new controller logging.Reviewed by Cursor Bugbot for commit 6230410. Bugbot is set up for automated code reviews on this repo. Configure here.