Repository: cgeo/cgeo (Java)

Issue:
Proposal to change Wherigo error message
On receiving an error message from a Wherigo cartridge, we currently print something like this:

```
Wherigo Problembericht Enginefehler: you hit a bug! please report at [openwig.googlecode.com](http://openwig.googlecode.com/) and i'll fix it for you! java.lang.RuntimeException: Tried to call nil stack trace: at @E:/webtempfiles/3641b205-3406-4cb4-bf03-100c6bfb6e67/_cartridge-new.enc:3314 at @E:/webtempfiles/3641b205-3406-4cb4-bf03-100c6bfb6e67/_cartridge-new.enc:2049 at @E:/webtempfiles/3641b205-3406-4cb4-bf03-100c6bfb6e67/_cartridge-new.enc:2046
```

This leads to users hitting the "send error to c:geo support" button, even though we can't really help them on support in 99.9% of all cases.

I propose to
- explain the user that they have hit an internal bug in the cartridge which only the cartridge author can fix,
- and maybe redirect them to the wherigo.com page for this cartridge, where the author of the cartridge is listed

on hitting errors that come from the Wherigo-internal engine.


Discussion: > redirect them to the wherigo.com page for this cartridge, where the author of the cartridge is listed

Is that possible now? Do we load the GUID somehow already when importing from file?

We could add a dialog to Provide the GUID for the Users in the negative case on Import.
Dirty hack would be to give cartridge authors a magic flag (e.g. CGEO_GUID) on the LUA cartridge object to control cgeo behaviour and skip the dialog
Could be connected with #16827 



Fix (patch):
diff --git a/main/src/main/java/cgeo/geocaching/apps/cache/WhereYouGoApp.java b/main/src/main/java/cgeo/geocaching/apps/cache/WhereYouGoApp.java
index 1f187f2b4b5..880727f29a8 100644
--- a/main/src/main/java/cgeo/geocaching/apps/cache/WhereYouGoApp.java
+++ b/main/src/main/java/cgeo/geocaching/apps/cache/WhereYouGoApp.java
@@ -30,7 +30,7 @@ public boolean isEnabled(@NonNull final Geocache cache) {
     public void navigate(@NonNull final Context context, @NonNull final Geocache cache) {
         final List<String> guids = WherigoUtils.getWherigoGuids(cache);
         if (!guids.isEmpty()) {
-            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(WherigoUtils.getWherigoUrl(guids.get(0)))));
+            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(WherigoUtils.getWherigoDownloadUrl(guids.get(0)))));
         }
     }
 
@@ -41,7 +41,7 @@ public static boolean isWhereYouGoInstalled() {
     public static void openWherigo(@NonNull final Activity activity, @NonNull final String guid) {
         // re-check installation state, might have changed since creating the view
         if (isWhereYouGoInstalled()) {
-            final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(WherigoUtils.getWherigoUrl(guid)));
+            final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(WherigoUtils.getWherigoDownloadUrl(guid)));
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             activity.startActivity(intent);
         } else {
diff --git a/main/src/main/java/cgeo/geocaching/wherigo/WherigoCartridgeDialogProvider.java b/main/src/main/java/cgeo/geocaching/wherigo/WherigoCartridgeDialogProvider.java
index 501347bdc01..31afab716b9 100644
--- a/main/src/main/java/cgeo/geocaching/wherigo/WherigoCartridgeDialogProvider.java
+++ b/main/src/main/java/cgeo/geocaching/wherigo/WherigoCartridgeDialogProvider.java
@@ -90,8 +90,10 @@ public Dialog createAndShowDialog(final Activity activity, final IWherigoDialogC
     }
 
     private void refreshGui(final WherigoCartridgeDetailsBinding binding) {
+        final String link = WherigoUtils.getWherigoDetailsUrl(cartridgeInfo.getCGuid());
         TextParam.text("**CGUID:** " + cartridgeInfo.getCGuid() + "  \n" +
             "**" + LocalizationUtils.getString(R.string.wherigo_author) + ":** " + cartridgeFile.author + "  \n" +
+            "**[" + LocalizationUtils.getString(R.string.cache_menu_browser) + "](" + link + ")**  \n" +
             "**" + LocalizationUtils.getString(R.string.cache_location) + ":** " + cartridgeInfo.getCartridgeLocation() + "  \n" +
             "**" + LocalizationUtils.getString(R.string.distance) + ":** " + WherigoUtils.getDisplayableDistance(WherigoLocationProvider.get().getLocation(), cartridgeInfo.getCartridgeLocation())
             ).setMarkdown(true).applyTo(binding.headerInformation);
diff --git a/main/src/main/java/cgeo/geocaching/wherigo/WherigoGame.java b/main/src/main/java/cgeo/geocaching/wherigo/WherigoGame.java
index b3da4f515a7..bda20328cef 100644
--- a/main/src/main/java/cgeo/geocaching/wherigo/WherigoGame.java
+++ b/main/src/main/java/cgeo/geocaching/wherigo/WherigoGame.java
@@ -78,6 +78,7 @@ public enum NotifyType {
     private File cartridgeCacheDir;
     private HtmlImage htmlImageGetter;
     private String lastError;
+    private String lastErrorCGuid;
     private boolean lastErrorNotSeen = false;
     private String contextGeocode;
     private String contextGeocacheName;
@@ -150,6 +151,7 @@ public void loadGame(@NonNull final ContentStorage.FileInformation cartridgeFile
             this.cartridgeInfo = new WherigoCartridgeInfo(cartridgeFileInfo, true, false);
             setCGuidAndDependentThings(this.cartridgeInfo.getCGuid());
             this.lastError = null;
+            this.lastErrorCGuid = null;
             this.lastErrorNotSeen = false;
 
             //try to restore context geocache
@@ -217,8 +219,14 @@ public String getLastError() {
         return lastError;
     }
 
+    @Nullable
+    public String getLastErrorCGuid() {
+        return lastErrorCGuid;
+    }
+
     public void clearLastError() {
         lastError = null;
+        lastErrorCGuid = null;
         notifyListeners(NotifyType.REFRESH);
     }
 
@@ -365,6 +373,7 @@ public void showError(final String errorMessage) {
             this.lastError = errorMessage +
                 " (Cartridge: " + getCartridgeName() + ", cguid: " + getCGuid() +
                 ", timestamp: " + Formatter.formatDateTime(System.currentTimeMillis()) + ")";
+            this.lastErrorCGuid = getCGuid();
             this.lastErrorNotSeen = true;
         }
         ViewUtils.showToast(null, R.string.wherigo_error_toast);
diff --git a/main/src/main/java/cgeo/geocaching/wherigo/WherigoUtils.java b/main/src/main/java/cgeo/geocaching/wherigo/WherigoUtils.java
index 530c0bfe1ad..f246fe8d1aa 100644
--- a/main/src/main/java/cgeo/geocaching/wherigo/WherigoUtils.java
+++ b/main/src/main/java/cgeo/geocaching/wherigo/WherigoUtils.java
@@ -71,7 +71,8 @@ public final class WherigoUtils {
     public static final TextParam TP_CANCEL_BUTTON = TextParam.id(R.string.cancel).setAllCaps(true).setImage(ImageParam.id(R.drawable.ic_menu_cancel));
 
     private static final Pattern PATTERN_CARTRIDGE_LINK = Pattern.compile("https?" + Pattern.quote("://") + "(?:www\\.)?" + Pattern.quote("wherigo.com/cartridge/") + "(?:details|download)" + Pattern.quote(".aspx?") + "[Cc][Gg][Uu][Ii][Dd]=([-0-9a-zA-Z]*)");
-    private static final String WHERIGO_URL_BASE = "https://www.wherigo.com/cartridge/download.aspx?CGUID=";
+    private static final String WHERIGO_DOWNLOAD_URL_BASE = "https://www.wherigo.com/cartridge/download.aspx?CGUID=";
+    private static final String WHERIGO_DETAILS_URL_BASE = "https://wherigo.com/cartridge/details.aspx?CGUID=";
 
     public static final GeopointConverter<ZonePoint> GP_CONVERTER = new GeopointConverter<>(
         gc -> new ZonePoint(gc.getLatitude(), gc.getLongitude(), 0),
@@ -363,8 +364,14 @@ public static List<String> getWherigoGuids(@Nullable final Geocache cache) {
     }
 
     @Nullable
-    public static String getWherigoUrl(@Nullable final String guid) {
-        return guid == null ? null : WHERIGO_URL_BASE + guid;
+    public static String getWherigoDetailsUrl(@Nullable final String guid) {
+        return guid == null ? null : WHERIGO_DETAILS_URL_BASE + guid;
+    }
+
+
+    @Nullable
+    public static String getWherigoDownloadUrl(@Nullable final String guid) {
+        return guid == null ? null : WHERIGO_DOWNLOAD_URL_BASE + guid;
     }
 
     @NonNull
diff --git a/main/src/main/java/cgeo/geocaching/wherigo/WherigoViewUtils.java b/main/src/main/java/cgeo/geocaching/wherigo/WherigoViewUtils.java
index a3de3d0ff1b..a0e9826261f 100644
--- a/main/src/main/java/cgeo/geocaching/wherigo/WherigoViewUtils.java
+++ b/main/src/main/java/cgeo/geocaching/wherigo/WherigoViewUtils.java
@@ -218,13 +218,14 @@ public static Dialog getQuickViewDialog(final Activity activity) {
 
     public static void showErrorDialog(final Activity activity) {
         final String lastError = WherigoGame.get().getLastError();
+        final String lastErrorCartridgeLink = WherigoUtils.getWherigoDetailsUrl(WherigoGame.get().getLastErrorCGuid());
         final String dialogErrorMessage = (lastError == null ? LocalizationUtils.getString(R.string.wherigo_error_game_noerror) :
-                LocalizationUtils.getString(R.string.wherigo_error_game_error, lastError));
+                LocalizationUtils.getString(R.string.wherigo_error_game_error, lastError, lastErrorCartridgeLink));
 
         final SimpleDialog dialog = SimpleDialog.of(activity)
                 .setTitle(TextParam.id(R.string.wherigo_error_title))
                 .setMessage(TextParam.text(dialogErrorMessage).setMarkdown(true))
-                .setPositiveButton(TextParam.id(R.string.copy));
+                .setPositiveButton(lastError == null ? TextParam.id(R.string.ok) : TextParam.id(R.string.copy));
 
         if (lastError != null) {
             dialog
@@ -232,8 +233,10 @@ public static void showErrorDialog(final Activity activity) {
                 .setNeutralAction(() -> WherigoGame.get().clearLastError());
         }
         dialog.show(() -> {
-            ClipboardUtils.copyToClipboard(lastError);
-            ActivityMixin.showToast(activity, R.string.copied_to_clipboard);
+            if (lastError != null) {
+                ClipboardUtils.copyToClipboard(lastError);
+                ActivityMixin.showToast(activity, R.string.copied_to_clipboard);
+            }
         });
         WherigoGame.get().clearLastErrorNotSeen();
     }
diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml
index 887175319ca..bafbb7fcff0 100644
--- a/main/src/main/res/values/strings.xml
+++ b/main/src/main/res/values/strings.xml
@@ -3009,7 +3009,7 @@
 
     <string name="wherigo_error_title">Wherigo Problem report</string>
     <string name="wherigo_error_game_noerror">No error reported by Wherigo Engine.</string>
-    <string name="wherigo_error_game_error">Error reported by Wherigo Engine:\n\n```\n%1$s\n```</string>
+    <string name="wherigo_error_game_error">Error reported by Wherigo Engine:\n\n```\n%1$s\n```\nYou may contact the author of the cartridge [here](%2$s)</string>
     <string name="wherigo_error_email">Wherigo Problem report\n\nEngine Error: %1$s\n\nWherigo Info: %2$s</string>
     <string name="wherigo_error_toast">Wherigo Engine reported an error. Open bug dialog for details.</string>