Skip to content

fix: Scope.clone incorrectly accesses tags#978

Merged
brustolin merged 2 commits into
getsentry:mainfrom
quaaantumdev:main
Aug 17, 2022
Merged

fix: Scope.clone incorrectly accesses tags#978
brustolin merged 2 commits into
getsentry:mainfrom
quaaantumdev:main

Conversation

@quaaantumdev

@quaaantumdev quaaantumdev commented Aug 6, 2022

Copy link
Copy Markdown
Contributor

📜 Description

fixed Scope.clone, incorrectly accesses tags and therefore crashes. Main branch currently extracts the keys from _tags to iterate over. This is all fine but it the tries to access the values via the keys-list which makes no sense, it's a list of strings, not a map where you could actually use the keys. I guess it's simply a typo due to "not so optimal" naming.

💡 Motivation and Context

Sentry crashing, error reporting with tags does not work. The following code will crash (current main branch):

Sentry.configureScope((scope) async {
  await scope.setTag('some.tag', 'value');
});

await Sentry.captureException(
  error,
  stackTrace: stackTrace,
  hint: 'here goes an error',
  withScope: (scope) async {
    try {
      await scope.setTag('class', className);
    } catch (err, stack) {
      print('ERROR: failed to add class in sentry: $err\n$stack');
    }
  },
);

💚 How did you test it?

running in production just fine :) currently using it via a pubspec.yaml git reference:

 sentry: # also remove override when fixed
    git:
      url: https://github.com/quaaantumdev/sentry-dart.git
      path: dart

would like to upgrade back to the official version once fixed

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

let's make sentry great again ;-)

#skip-changelog

@brustolin brustolin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brustolin
brustolin enabled auto-merge (squash) August 8, 2022 06:47
@codecov-commenter

codecov-commenter commented Aug 8, 2022

Copy link
Copy Markdown

Codecov Report

Merging #978 (0cc8cbe) into main (1998016) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #978   +/-   ##
=======================================
  Coverage   91.14%   91.14%           
=======================================
  Files           9        9           
  Lines         192      192           
=======================================
  Hits          175      175           
  Misses         17       17           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@marandaneto

Copy link
Copy Markdown
Contributor

@quaaantumdev thanks for the PR, can you explain which issue are you getting? what's the error?
Please elaborate on:

incorrectly accesses tags and therefore crashes

@brustolin

Copy link
Copy Markdown
Contributor

By incorrectly accesses tags and therefore crashes he means the variable name.

Old code:

final tags = List.from(_tags.keys); //tags is a list of string
     for (final tag in tags) {
       final value = tags[tag]; //tags is not a dictionary, we should be reading from _tags passing the key
       if (value != null) {
         clone._setTagSync(tag, value);
       }
    }

@brustolin
brustolin merged commit 2ada18f into getsentry:main Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants