Skip to content

Capture exception with setContexts not working #2867

@geosebas

Description

@geosebas

Platform

Flutter Mobile iOS

Obfuscation

Disabled

Debug Info

Enabled

Doctor

[✓] Flutter (Channel stable, 3.27.3, on macOS 15.3.1 24D70 darwin-arm64, locale fr-FR)
• Flutter version 3.27.3 on channel stable at /Users/geoffreysebastianelli/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c519ee916e (3 months ago), 2025-01-21 10:32:23 -0800
• Engine revision e672b006cb
• Dart version 3.6.1
• DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at /Users/geoffreysebastianelli/Library/Android/sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16E140
• CocoaPods version 1.16.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.99.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.108.0

[✓] Connected device (7 available)
• 23129RN51X (mobile) • NNHQMJYDUOOJ7H8D • android-arm • Android 14 (API 34)
• iPhone de Geoffrey (mobile) • 00008120-000221361432201E • ios • iOS 18.3.2 22D82
• iPhone 16 Pro Max (mobile) • 896BCC39-6989-466D-A237-187517449B76 • ios • com.apple.CoreSimulator.SimRuntime.iOS-18-2 (simulator)
• iPhone SE (3rd generation) (mobile) • 3C4A452A-DC93-40E3-8A72-855058081AF1 • ios • com.apple.CoreSimulator.SimRuntime.iOS-18-2 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.3.1 24D70 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.3.1 24D70 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 135.0.7049.85
! Error: Browsing on the local area network for iPhone 8 de Toubi (2). Ensure the device is unlocked and attached with a cable or associated with the same local area
network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
• All expected network resources are available.

• No issues found!

Version

8.14.1

Steps to Reproduce

try {
  await Sentry.captureException(
    Exception(message ?? 'Unable to get message from body : $body'),
    stackTrace: StackTrace.current,
    withScope: (scope) async {
      // Working with a setTag 
      // await scope.setTag('aaa', 'bbb'); 

      // Not working with setContexts
      await scope.setContexts('response', 'vvv');
    },
  );
} catch (e) {
// I don't get any error here
  debugPrint('Error sending Sentry message: $e');
}

Expected Result

Sending event to Sentry

Actual Result

Before adding setContexts everything was working nicely.
I want to send complex data so I can't use setTag.

I got this error in the flutter logger :

[error] Error while capturing exception

type '_Map<String, dynamic>' is not a subtype of type 'SentryResponse?'

#0      Contexts.response (package:sentry/src/protocol/contexts.dart:141:39)
#1      Contexts.clone (package:sentry/src/protocol/contexts.dart:268:17)
#2      Scope.applyToEvent (package:sentry/src/scope.dart:320:15)
#3      SentryClient.captureEvent (package:sentry/src/sentry_client.dart:129:35)
#4      Hub.captureException (package:sentry/src/hub.dart:164:38)
<asynchronous suspension>
#5      DefaultTaskQueue.enqueue (package:sentry/src/transport/task_queue.dart:43:16)
<asynchronous suspension>
#6      UserService.sendVerificationPhoto (package:livtoo_lib/src/core/services/user_service.dart:317:11)
<asynchronous suspension>
#7      UserRepository.verifyPhoto (package:livtoo_app/core/repositories/user_repository.dart:489:5)
<asynchronous suspension>
#8      RegisterManager.verifyPhoto (package:livtoo_app/ui/pages/register/register_manager.dart:294:7)
<asynchronous suspension>

Are you willing to submit a PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Needs Investigation

    Status

    Waiting for: Community

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions