Give more meaningful error messages.

This commit is contained in:
Stephen Heumann 2019-04-19 00:49:46 -05:00
parent dcb6aa4d6b
commit c3de6f0588
6 changed files with 76 additions and 11 deletions

View File

@ -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

View File

@ -6,6 +6,7 @@
#pragma noroot
#endif
#include <quickdraw.h>
#include <window.h>
#include <stdio.h>
@ -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);
}

View File

@ -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"
};

View File

@ -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);

57
netdiskerror.c Normal file
View File

@ -0,0 +1,57 @@
#pragma noroot
#include <stdio.h>
#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;
}

View File

@ -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);