7430183fd67efb62e1c8c56df098177b20722379
braney
  Sun Jun 22 11:25:23 2014 -0700
some slightly better error handling on hub connects
diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c
index 8337d6c..055fdd7 100644
--- src/hg/lib/hubConnect.c
+++ src/hg/lib/hubConnect.c
@@ -508,35 +508,34 @@
 static char  *checkForNew( struct cart *cart)
 /* see if the user just typed in a new hub url, return id if so */
 {
 struct hubConnectStatus *hub;
 char *url = cartOptionalString(cart, hgHubDataText);
 char *newDatabase = NULL;
 
 if (url == NULL)
     return NULL;
 
 trimSpaces(url);
 hub = getAndSetHubStatus( cart, url, TRUE);
 cartRemove(cart, hgHubDataText);
 
 char *wantFirstDb = cartOptionalString(cart, hgHubDoFirstDb);
-if (wantFirstDb != NULL)
-    {
+if ((wantFirstDb != NULL) && (hub->trackHub != NULL))
     newDatabase = hub->trackHub->defaultDb;
-    fprintf(stderr, "getting defaultDb %s\n", newDatabase);
-    }
+
+cartRemove(cart, hgHubDoFirstDb);
 return newDatabase;
 }
 
 unsigned hubResetError(char *url)
 /* clear the error for this url in the hubStatus table,return the id */
 {
 struct sqlConnection *conn = hConnectCentral();
 char query[512];
 
 sqlSafef(query, sizeof(query), "select id from %s where hubUrl = \"%s\"", getHubStatusTableName(), url);
 unsigned id = sqlQuickNum(conn, query);
 
 if (id == 0)
     errAbort("could not find url %s in status table (%s)\n", 
 	url, getHubStatusTableName());
@@ -576,31 +575,34 @@
 {
 /* clear the hubStatus table */
 unsigned id = hubClearStatus(url);
 
 /* remove the cart variable */
 char buffer[1024];
 safef(buffer, sizeof buffer, "hgHubConnect.hub.%d", id);
 cartRemove(cart, buffer);
 }
 
 void hubUpdateStatus(char *errorMessage, struct hubConnectStatus *hub)
 /* set the error message in the hubStatus table */
 {
 struct sqlConnection *conn = hConnectCentral();
 char query[64 * 1024];
-struct trackHub *tHub = hub->trackHub;
+struct trackHub *tHub = NULL;
+
+if (hub != NULL)
+    tHub = hub->trackHub;
 
 if (errorMessage != NULL)
     {
     // make sure there is no newline at the end.  This should be unneccesary
     // but there are many, many places where newlines are added in calls
     // to warn and errAbort
     char buffer[64 * 1024];
     safecpy(buffer, sizeof buffer, errorMessage);
     while (lastChar(buffer) == '\n')
 	buffer[strlen(buffer) - 1] = '\0';
     sqlSafef(query, sizeof(query),
 	"update %s set errorMessage=\"%s\", lastNotOkTime=now() where id=%d",
 	getHubStatusTableName(), buffer, hub->id);
     sqlUpdate(conn, query);
     }