Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigator.pushAndRemoveUntil throws exception in Bugsnag #242

Merged
merged 9 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## TBD

- Fixed: Navigator.pushAndRemoveUntil throws exception [#242](https://github.com/bugsnag/bugsnag-flutter/pull/242)

## 3.1.0 (2024-04-09)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ Void start(@Nullable JSONObject args) throws Exception {
? new Configuration(arguments.getString("apiKey"))
: Configuration.load(context);

configuration.setAppType(arguments.optString("appType", configuration.getAppType()));
configuration.setAppVersion(arguments.optString("appVersion", configuration.getAppVersion()));
configuration.setAppType(getString(arguments, "appType", configuration.getAppType()));
configuration.setAppVersion(getString(arguments, "appVersion", configuration.getAppVersion()));
configuration.setAutoTrackSessions(arguments.optBoolean("autoTrackSessions", configuration.getAutoTrackSessions()));
configuration.setAutoDetectErrors(arguments.optBoolean("autoDetectErrors", configuration.getAutoDetectErrors()));
configuration.setContext(arguments.optString("context", configuration.getContext()));
configuration.setContext(getString(arguments, "context", configuration.getContext()));
configuration.setLaunchDurationMillis(arguments.optLong("launchDurationMillis", configuration.getLaunchDurationMillis()));
configuration.setSendLaunchCrashesSynchronously(arguments.optBoolean("sendLaunchCrashesSynchronously", configuration.getSendLaunchCrashesSynchronously()));
configuration.setMaxBreadcrumbs(arguments.optInt("maxBreadcrumbs", configuration.getMaxBreadcrumbs()));
configuration.setMaxPersistedEvents(arguments.optInt("maxPersistedEvents", configuration.getMaxPersistedEvents()));
configuration.setMaxPersistedSessions(arguments.optInt("maxPersistedSessions", configuration.getMaxPersistedSessions()));
configuration.setMaxStringValueLength(arguments.optInt("maxStringValueLength", configuration.getMaxStringValueLength()));
configuration.setReleaseStage(arguments.optString("releaseStage", configuration.getReleaseStage()));
configuration.setReleaseStage(getString(arguments, "releaseStage", configuration.getReleaseStage()));
configuration.setPersistUser(arguments.optBoolean("persistUser", configuration.getPersistUser()));

if (arguments.has("redactedKeys")) {
Expand All @@ -133,9 +133,9 @@ Void start(@Nullable JSONObject args) throws Exception {
JSONObject user = arguments.optJSONObject("user");
if (user != null) {
configuration.setUser(
user.optString("id", null),
user.optString("email", null),
user.optString("name", null)
getString(user, "id"),
getString(user, "email"),
getString(user, "name")
);
}

Expand Down Expand Up @@ -228,9 +228,9 @@ JSONObject getUser(@Nullable JSONObject args) {
Void setUser(@Nullable JSONObject user) {
if (user != null) {
Bugsnag.setUser(
(String) user.opt("id"),
(String) user.opt("email"),
(String) user.opt("name")
getString(user, "id"),
getString(user, "email"),
getString(user, "name")
);
} else {
Bugsnag.setUser(null, null, null);
Expand All @@ -241,7 +241,7 @@ Void setUser(@Nullable JSONObject user) {

Void setContext(@Nullable JSONObject args) {
if (args != null) {
Bugsnag.setContext((String) args.opt("context"));
Bugsnag.setContext(getString(args, "context"));
}

return null;
Expand All @@ -253,9 +253,9 @@ String getContext(@Nullable JSONObject args) {

Void leaveBreadcrumb(@Nullable JSONObject args) throws Exception {
if (args != null &&
args.has("name") &&
hasString(args, "name") &&
args.has("metaData") &&
args.has("type")) {
hasString(args, "type")) {
Bugsnag.leaveBreadcrumb(args.getString("name"),
JsonHelper.unwrap(args.getJSONObject("metaData")),
JsonHelper.unpackBreadcrumbType(args.getString("type")));
Expand All @@ -279,7 +279,7 @@ Void addFeatureFlags(@Nullable JSONArray args) {
}

Void clearFeatureFlag(@Nullable JSONObject args) throws JSONException {
if (args != null && args.has("name")) {
if (args != null && hasString(args, "name")) {
Bugsnag.clearFeatureFlag(args.getString("name"));
}
return null;
Expand All @@ -291,7 +291,7 @@ Void clearFeatureFlags(@Nullable JSONObject args) {
}

Void addMetadata(@Nullable JSONObject args) throws JSONException {
if (args == null || !args.has("section") || !args.has("metadata")) {
if (args == null || !hasString(args,"section") || args.has("metadata")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting

Suggested change
if (args == null || !hasString(args,"section") || args.has("metadata")) {
if (args == null || !hasString(args, "section") || args.has("metadata")) {

return null;
}

Expand All @@ -303,11 +303,11 @@ Void addMetadata(@Nullable JSONObject args) throws JSONException {
}

Void clearMetadata(@Nullable JSONObject args) throws JSONException {
if (args == null || !args.has("section")) {
if (args == null || !hasString(args,"section")) {
robert-smartbear marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

if (args.has("key")) {
if (hasString(args,"key")) {
robert-smartbear marked this conversation as resolved.
Show resolved Hide resolved
Bugsnag.clearMetadata(args.getString("section"), args.getString("key"));
} else {
Bugsnag.clearMetadata(args.getString("section"));
Expand All @@ -317,7 +317,7 @@ Void clearMetadata(@Nullable JSONObject args) throws JSONException {
}

JSONObject getMetadata(@Nullable JSONObject args) throws JSONException {
if (args == null || !args.has("section")) {
if (args == null || !hasString(args,"section")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting

Suggested change
if (args == null || !hasString(args,"section")) {
if (args == null || !hasString(args,"section")) {

return null;
}

Expand Down Expand Up @@ -403,4 +403,21 @@ JSONObject deliverEvent(@Nullable JSONObject eventJson) {
client.deliverEvent(event);
return null;
}

@Nullable String getString(JSONObject args, String key) {
if (!args.has(key)) {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this check is redundant, if args.get(key) returns null the instanceof String check will fail and we return null.

Object value = args.opt(key);
return value instanceof String ? (String) value : null;
}

@Nullable String getString(JSONObject args, String key, @Nullable String fallback) {
String value = getString(args, key);
return value != null ? value : fallback;
}

boolean hasString(JSONObject args, String key) {
return getString(args, key) != null;
}
}