From c3de6f05884b28d125c22efbfacf34b2fd28b65f Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 19 Apr 2019 00:49:46 -0500 Subject: [PATCH] Give more meaningful error messages. --- Makefile | 2 +- browserutil.c | 10 +++++---- diskbrowser.rez | 12 +++++++---- diskmount.c | 2 ++ netdiskerror.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ netdiskerror.h | 4 ++-- 6 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 netdiskerror.c diff --git a/Makefile b/Makefile index 4ac90a7..7725bc1 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ JSONTEST_PROG = jsontest HTTPTEST_OBJS = httptest.a hostname.a http.a readtcp.a seturl.a strcasecmp.a tcpconnection.a urlparser.a HTTPTEST_PROG = httptest -DISKBROWSER_OBJS = diskbrowser.a browserevents.a browserwindow.a browserutil.a diskmount.a disksearch.a hostname.a http.a json.a jsonutil.a readtcp.a seturl.a strcasecmp.a tcpconnection.a urlparser.a asprintf.a +DISKBROWSER_OBJS = diskbrowser.a browserevents.a browserwindow.a browserutil.a diskmount.a disksearch.a hostname.a http.a json.a jsonutil.a readtcp.a seturl.a strcasecmp.a tcpconnection.a urlparser.a netdiskerror.a asprintf.a DISKBROWSER_RSRC = diskbrowser.rez DISKBROWSER_PROG = DiskBrowser diff --git a/browserutil.c b/browserutil.c index 6240a23..052423c 100644 --- a/browserutil.c +++ b/browserutil.c @@ -6,6 +6,7 @@ #pragma noroot #endif +#include #include #include @@ -16,14 +17,15 @@ #include "readtcp.h" #include "tcpconnection.h" #include "json.h" +#include "netdiskerror.h" void ShowErrorAlert(enum NetDiskError error, int alertNumber) { - char numStr[6] = ""; - char *subs[1] = {numStr}; - - snprintf(numStr, sizeof(numStr), "%u", error); + char *subs[1]; + subs[0] = ErrorString(error); + + InitCursor(); AlertWindow(awResource+awCString+awButtonLayout, (Pointer)subs, alertNumber); } diff --git a/diskbrowser.rez b/diskbrowser.rez index 34e1e22..d6eb4d4 100644 --- a/diskbrowser.rez +++ b/diskbrowser.rez @@ -163,14 +163,18 @@ resource rPString(mountDiskButton) { "Mount Disk" }; #define mountErrorAlert 3001 resource rAlertString (searchErrorAlert) { - "52/" - "There was an error when searching for disks. (error code *0)" + "72/" + "There was an error when searching for disks.\n" + "\n" + "*0" "/^#0\$00" }; resource rAlertString (mountErrorAlert) { - "52/" - "There was an error when trying to mount a disk. (error code *0)" + "72/" + "There was an error when trying to mount a disk.\n" + "\n" + "*0" "/^#0\$00" }; diff --git a/diskmount.c b/diskmount.c index ecd36ea..634acae 100644 --- a/diskmount.c +++ b/diskmount.c @@ -133,6 +133,8 @@ static void MountFile(char *itemID, char *fileName) { devName.length = snprintf(devName.text, sizeof(devName.text), ".D%u", mountURLRec.devNum); wantToOpenWindow = 2; + } else { + ShowErrorAlert(mountURLRec.result, mountErrorAlert); } free(fileURL); diff --git a/netdiskerror.c b/netdiskerror.c new file mode 100644 index 0000000..ee12e9d --- /dev/null +++ b/netdiskerror.c @@ -0,0 +1,57 @@ +#pragma noroot + +#include +#include "netdiskerror.h" + +static char errorBuf[20]; + +char *ErrorString(enum NetDiskError err) { + switch (err) { + case NO_DIBS_AVAILABLE: + return "No more disks can be mounted via NetDisk."; + case OUT_OF_MEMORY: + return "Out of memory."; + + /* SetURL errors */ + case NAME_LOOKUP_FAILED: + return "The archive.org server could not be found."; + + /* StartTCPConnection and DoHTTPRequest errors */ + case NETWORK_ERROR: + return "A network error was encountered."; + case NO_RESPONSE: + return "The server did not respond to a request."; + case INVALID_RESPONSE: + return "The response from the server was invalid."; + case EXCESSIVE_REDIRECTS: + return "There were too many HTTP redirects."; + case UNSUPPORTED_RESPONSE: + return "An unsupported response was received from the server."; + case UNSUPPORTED_HEADER_VALUE: + return "An unsupported header value was received from the server."; + case REDIRECT_ERROR: + return "An error was encountered when trying to redirect to the " + "location specified by the server."; + case NOT_DESIRED_CONTENT: + return "The server did not send the content that was expected."; + case DIFFERENT_LENGTH: + return "The length of the file on the server was different from what " + "was expected."; + + /* File format errors */ + case UNSUPPORTED_2IMG_FILE: + return "This 2mg file is not supported by NetDisk."; + case NOT_MULTIPLE_OF_BLOCK_SIZE: + return "The file is not a multiple of 512 bytes. It may not be a disk " + "image file, or is not in a supported format."; + + /* JSON processing errors */ + case JSON_PARSING_ERROR: + case NOT_EXPECTED_CONTENTS: + return "The response from the server was invalid. " + "It may not support your query."; + } + + snprintf(errorBuf, sizeof(errorBuf), "Error code %i.", err); + return errorBuf; +} diff --git a/netdiskerror.h b/netdiskerror.h index 5a4f35c..342f7f4 100644 --- a/netdiskerror.h +++ b/netdiskerror.h @@ -48,8 +48,8 @@ enum NetDiskError { /* - * Return a string describing the error. It may contain the substitution - * string "*0", which should be replaced by the error number. + * Return a string describing the error. It is only guaranteed to be valid + * until the next call to ErrorString(). */ char *ErrorString(enum NetDiskError err);