Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
minVersion: '0.17.1'
github:
owner: getsentry
repo: sentry-dart
changelogPolicy: auto
statusProvider:
name: github
artifactProvider:
name: none
targets:
- name: github
- name: registry
type: sdk
config:
canonical: "pub:sentry"
- name: registry
type: sdk
config:
canonical: "pub:sentry_flutter"
31 changes: 0 additions & 31 deletions .github/workflows/changelog-validation.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Danger"
on:
pull_request:
types: [opened, synchronize, reopened, edited, ready_for_review]

jobs:
build:
name: Changelog
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: npx danger ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 changes: 20 additions & 23 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,26 @@ jobs:
flutter format -n --set-exit-if-changed ./
flutter analyze

# pana fails when the package depends on a package which is not stable yet (sentry.4.x.x-beta)
# once it's GA and API is stable, we could uncomment this, this is gonna be run manually
# via ./tools/presubmit.sh
# package-analysis:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: axel-op/dart-package-analyzer@v3
# id: analysis
# with:
# githubToken: ${{ secrets.GITHUB_TOKEN }}
# relativePath: flutter/
# - name: Check scores
# env:
# TOTAL: ${{ steps.analysis.outputs.total }}
# TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
# run: |
# PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
# if (( $PERCENTAGE < 100 ))
# then
# echo Score too low!
# exit 1
# fi
package-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: axel-op/dart-package-analyzer@d56ba070e9dcacc6d8ba48a41938b1e2b973de41
id: analysis
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
relativePath: flutter/
- name: Check scores
env:
TOTAL: ${{ steps.analysis.outputs.total }}
TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
run: |
PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
if (( $PERCENTAGE < 90 ))
then
echo Score too low!
exit 1
fi

pod-lint:
runs-on: macos-latest
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# vNext
# Unreleased

* Fix: Do not append stack trace to the exception if there are no frames
* Fix: Empty DSN disables the SDK and runs the App

# 4.0.6

* Refactoring: Migrate Sentry Dart to null safety
* Fix: captureMessage defaults SentryLevel to info
* Fix: SentryEvent.throwable returns the unwrapped throwable instead of the throwableMechanism
* Feat: Support enableNativeCrashHandling on iOS

# 4.0.5

Expand Down
93 changes: 93 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const PR_NUMBER = danger.github.pr.number;
const PR_LINK = `(#${PR_NUMBER})`;

const CHANGELOG_SUMMARY_TITLE = `Instructions and example for changelog`;
const CHANGELOG_BODY = `Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section under the following heading:

To the changelog entry, please add a link to this PR (consider a more descriptive message):`;

const CHANGELOG_END_BODY = `If none of the above apply, you can opt out by adding _#skip-changelog_ to the PR description.`;

function getCleanTitleWithPrLink() {
const title = danger.github.pr.title;
return title.split(": ").slice(-1)[0].trim().replace(/\.+$/, "") + PR_LINK;
}

function getChangelogDetailsHtml() {
return `
<details>
<summary><b>\`${CHANGELOG_SUMMARY_TITLE}\`$</b></summary>

\`${CHANGELOG_BODY}\`

\`\`\`md
- ${getCleanTitleWithPrLink()}
\`\`\`

\`${CHANGELOG_END_BODY}\`
</details>
`;
}

function getChangelogDetailsTxt() {
return CHANGELOG_SUMMARY_TITLE + '\n' +
CHANGELOG_BODY + '\n' +
getCleanTitleWithPrLink() + '\n' +
CHANGELOG_END_BODY;
}

function HasPermissionToComment(){
return danger.github.pr.head.repo.git_url == danger.github.pr.base.repo.git_url;
}

async function containsChangelog(path) {
const contents = await danger.github.utils.fileContents(path);
return contents.includes(PR_LINK);
}

async function checkChangelog() {
const skipChangelog =
danger.github && (danger.github.pr.body + "").includes("#skip-changelog");
if (skipChangelog) {
return;
}

const hasChangelog = await containsChangelog("CHANGELOG.md");

if (!hasChangelog)
{
if (HasPermissionToComment())
{
fail("Please consider adding a changelog entry for the next release.");
markdown(getChangelogDetailsHtml());
}
else
{
//Fallback
console.log("Please consider adding a changelog entry for the next release.");
console.log(getChangelogDetailsTxt());
process.exitCode = 1;
}
}
}

async function checkIfFeature() {
const title = danger.github.pr.title;
if (title.startsWith('feat:') && HasPermissionToComment()){
message('Do not forget to update <a href="https://github.com/getsentry/sentry-docs">Sentry-docs</a> with your feature once the pull request gets approved.');
}
}

async function checkAll() {
// See: https://spectrum.chat/danger/javascript/support-for-github-draft-prs~82948576-ce84-40e7-a043-7675e5bf5690
const isDraft = danger.github.pr.mergeable_state === "draft";

if (isDraft) {
return;
}

await checkIfFeature();
await checkChangelog();
}

schedule(checkAll);
2 changes: 1 addition & 1 deletion dart/example_web/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Future<void> captureMessage() async {
if (sentryId != SentryId.empty()) {
querySelector('#messageResult').style.display = 'block';
}
await Sentry.close();
Sentry.close();
}

Future<void> captureException() async {
Expand Down
9 changes: 5 additions & 4 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Hub {
} catch (err) {
_options.logger(
SentryLevel.error,
'Error while capturing event with id: ${event.eventId.toString()}',
'Error while capturing event with id: ${event.eventId}, error: $err',
);
} finally {
_lastEventId = sentryId;
Expand Down Expand Up @@ -161,7 +161,7 @@ class Hub {
} catch (err) {
_options.logger(
SentryLevel.error,
'Error while capturing message with id: $message',
'Error while capturing message with id: $message, error: $err',
);
} finally {
_lastEventId = sentryId;
Expand Down Expand Up @@ -221,12 +221,13 @@ class Hub {
}

final item = _peek();

try {
item.client.close();
} catch (err) {
_options.logger(
SentryLevel.error,
'Error while closing the Hub.',
'Error while closing the Hub, error: $err',
);
}

Expand All @@ -249,7 +250,7 @@ class Hub {
} catch (err) {
_options.logger(
SentryLevel.error,
"Error in the 'configureScope' callback.",
"Error in the 'configureScope' callback, error: $err",
);
}
}
Expand Down
19 changes: 15 additions & 4 deletions dart/lib/src/protocol/sentry_event.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:meta/meta.dart';

import '../protocol.dart';
import '../throwable_mechanism.dart';
import '../utils.dart';

/// An event to be reported to Sentry.io.
Expand All @@ -24,7 +25,7 @@ class SentryEvent {
this.environment,
this.message,
this.transaction,
this.throwable,
dynamic throwable,
this.stackTrace,
this.exception,
this.level,
Expand All @@ -40,7 +41,8 @@ class SentryEvent {
tags = tags != null ? Map.from(tags) : null,
extra = extra != null ? Map.from(extra) : null,
fingerprint = fingerprint != null ? List.from(fingerprint) : null,
breadcrumbs = breadcrumbs != null ? List.from(breadcrumbs) : null;
breadcrumbs = breadcrumbs != null ? List.from(breadcrumbs) : null,
_throwable = throwable;

/// Refers to the default fingerprinting algorithm.
///
Expand Down Expand Up @@ -80,12 +82,21 @@ class SentryEvent {
/// Generally an event either contains a [message] or an [exception].
final Message? message;

final dynamic _throwable;

/// An object that was thrown.
///
/// It's `runtimeType` and `toString()` are logged.
/// If it's an Error, with a stackTrace, the stackTrace is logged.
/// If this behavior is undesirable, consider using a custom formatted [message] instead.
final dynamic throwable;
dynamic get throwable => (_throwable is ThrowableMechanism)
? (_throwable as ThrowableMechanism).throwable
: _throwable;

/// A Throwable decorator that holds a Mechanism related to the decorated Throwable
///
/// Use the 'throwable' directly if you don't want the decorated Throwable
dynamic get throwableMechanism => _throwable;

/// an optional attached StackTrace
/// used when event has no throwable or exception, see [SentryOptions.attachStacktrace]
Expand Down Expand Up @@ -197,7 +208,7 @@ class SentryEvent {
modules: (modules != null ? Map.from(modules) : null) ?? this.modules,
message: message ?? this.message,
transaction: transaction ?? this.transaction,
throwable: throwable ?? this.throwable,
throwable: throwable ?? _throwable,
exception: exception ?? this.exception,
stackTrace: stackTrace ?? this.stackTrace,
level: level ?? this.level,
Expand Down
10 changes: 4 additions & 6 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ class Sentry {
}

// let's set the default values to options
if (!_setDefaultConfiguration(options)) {
return;
if (_setDefaultConfiguration(options)) {
final hub = currentHub;
_hub = Hub(options);
hub.close();
}

final hub = currentHub;
_hub = Hub(options);
hub.close();

// execute integrations after hub being enabled
if (appRunner != null) {
var runIntegrationsAndAppRunner = () async {
Expand Down
6 changes: 3 additions & 3 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SentryClient {
} catch (err) {
_options.logger(
SentryLevel.error,
'The BeforeSend callback threw an exception',
'The BeforeSend callback threw an exception, error: $err',
);
}
if (preparedEvent == null) {
Expand All @@ -112,9 +112,9 @@ class SentryClient {

if (event.exception != null) return event;

if (event.throwable != null) {
if (event.throwableMechanism != null) {
final sentryException = _exceptionFactory
.getSentryException(event.throwable, stackTrace: stackTrace);
.getSentryException(event.throwableMechanism, stackTrace: stackTrace);

return event.copyWith(exception: sentryException);
}
Expand Down
9 changes: 6 additions & 3 deletions dart/lib/src/sentry_exception_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ class SentryExceptionFactory {

SentryStackTrace? sentryStackTrace;
if (stackTrace != null) {
sentryStackTrace = SentryStackTrace(
frames: _stacktraceFactory.getStackFrames(stackTrace),
);
final frames = _stacktraceFactory.getStackFrames(stackTrace);
if (frames.isNotEmpty) {
sentryStackTrace = SentryStackTrace(
frames: frames,
);
}
}

// if --obfuscate feature is enabled, 'type' won't be human readable.
Expand Down
Loading