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

Handle throwable with null message in REPL #3081

Open
wants to merge 5 commits into
base: ucr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,10 @@
;; Commented out -- we only send reports from the setting menu choice
;; (com.google.appinventor.components.runtime.ReplApplication:reportError ex)
(if isrepl
(when ((this):toastAllowed)
XomaDev marked this conversation as resolved.
Show resolved Hide resolved
(let ((message (if (instance? ex java.lang.Error) (ex:toString) (ex:getMessage))))
XomaDev marked this conversation as resolved.
Show resolved Hide resolved
(send-error message)
((android.widget.Toast:makeText (this) message 5):show)))

(com.google.appinventor.components.runtime.util.RuntimeErrorAlert:alert
(this)
(this):toastAllowed
(this):toastAllowed
(ex:getMessage)
(if (instance? ex YailRuntimeError) ((as YailRuntimeError ex):getErrorType) "Runtime Error")
"End Application")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,17 @@ private static File getFile(final String fileName, String cookieValue, String as
Form form = Form.getActiveForm();
if (depth > 1) {
synchronized (semaphore) { // We are protecting the inError variable
if (inError) {
return null;
} else {
if (!inError) {
inError = true;
form.runOnUiThread(new Runnable() {
public void run() {
RuntimeErrorAlert.alert(Form.getActiveForm(), "Unable to load file: " + fileName,
public void run() {
RuntimeErrorAlert.alert(Form.getActiveForm(), false, true,
"Unable to load file: " + fileName,
"Error!", "End Application");
}
});
return null;
}
});
}
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.widget.Toast;

/**
* Shows a runtime error alert with a single button. Pressing the button will
Expand All @@ -19,22 +20,33 @@
* @author [email protected] (Hal Abelson)
*/
public final class RuntimeErrorAlert {

private static final String TAG = "RuntimeErrorAlert";

public static void alert(final Object context,
XomaDev marked this conversation as resolved.
Show resolved Hide resolved
final String message, final String title,final String buttonText) {
Log.i("RuntimeErrorAlert", "in alert");
boolean sendError,
boolean toastAllowed,
String message,
String title,
String buttonText) {
Log.e(TAG, "alert(" + message + ", " + title + ", " + buttonText);
if (message == null) {
// do not pass null, or it will result in a crash
message = title + " <No error message>";
}
if (toastAllowed) {
Toast.makeText((Context) context, message, Toast.LENGTH_SHORT).show();
}
if (sendError) {
RetValManager.sendError(message);
}
AlertDialog alertDialog = new AlertDialog.Builder((Context) context).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setButton(buttonText, new DialogInterface.OnClickListener() {
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, buttonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
((Activity) context).finish();
}});
if (message == null) {
// Avoid passing null to Log.e, which would cause a NullPointerException.
Log.e(RuntimeErrorAlert.class.getName(), "No error message available");
} else {
Log.e(RuntimeErrorAlert.class.getName(), message);
}
alertDialog.show();
}
}