4aeb7ec91d0af424b00b2a5aa5bb205a2afa03e6
max
  Tue Dec 12 00:46:09 2023 -0800
improving jksql error message when no ~/.hg.conf file was found, refs #32741, also improving error message when the hgcentral server is not working and the CGI is running on the RR, email with browser-staff on Oct 23 and group meeting about what to do when hgcentral is down, no redmine

diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index 02be05e..e9c9cd6 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -407,32 +407,32 @@
 if (sp==NULL || sp->name==NULL)
     return NULL;
 char *failoverProfName = catTwoStrings(failoverProfPrefix, sp->name);
 struct sqlProfile *failoverProf = sqlProfileGet(failoverProfName, database);
 freez(&failoverProfName);
 return failoverProf;
 }
 
 static struct sqlProfile* sqlProfileMustGet(char *profileName, char *database)
 /* lookup a profile using the profile resolution algorithm or die trying */
 {
 struct sqlProfile* sp = sqlProfileGet(profileName, database);
 if (sp == NULL)
     {
     if (profileName == NULL)
-        errAbort("can't find database %s in hg.conf, should have a default named \"db\"",
-                 database);
+        errAbort("can't find mysql connection info for database %s in hg.conf or ~/.hg.conf, should have a default profile named \"db\", so values for at least db.host, "
+                "db.user and db.password. See http://genomewiki.ucsc.edu/index.php/Hg.conf", database);
     else if (sameWord(profileName, "backupcentral"))
         errAbort("can't find profile %s in hg.conf. This error most likely indicates that the "
             "Genome Browser could not connect to MySQL/MariaDB. Either the databases server is not running"
             "or the database connection socket indicated in hg.conf is not the one used by your server.", 
             profileName);
     else if (database == NULL)
         errAbort("can't find profile %s in hg.conf", profileName);
     else
         errAbort("can't find profile %s for database %s in hg.conf", profileName, database);
     }
 return sp;
 }
 
 struct slName* sqlProfileGetNames()
 /* Get a list of all profile names. slFreeList result when done */
@@ -1074,30 +1074,40 @@
 	}
     freeDlList(&sqlOpenConnections);
     }
 }
 
 static void sqlInitTracking(void)
 /* Initialize tracking and freeing of resources. */
 {
 if (sqlOpenConnections == NULL)
     {
     sqlOpenConnections = newDlList();
     atexit(sqlCleanupAll);
     }
 }
 
+static bool sqlIsUcscServer()
+/* Return TRUE if this is one of our own servers at UCSC */
+{
+// partially copied from hdb.c, but avoids dependendcy on hdb.c
+char *httpHost = getenv("HTTP_HOST");
+if (httpHost==NULL) // this is not running as a CGI, but a command-line program
+    return FALSE;
+return (containsStringNoCase(httpHost, ".ucsc.edu")!=NULL);
+}
+
 static struct sqlConnection *sqlConnRemoteFillIn(struct sqlConnection *sc, 
 					   struct sqlProfile *sp,
                                            char *database, boolean abort, boolean addAsOpen)
 /* Fill the sqlConnection object: Connect to database somewhere as somebody.
  * Database maybe NULL to just connect to the server.  If abort is set display
  * error message and abort on error. This is the core function that connects to
  * a MySQL server. */
 {
 MYSQL *conn;
 long deltaTime;
 
 sqlInitTracking();
 
 sc->resultList = newDlList();
 
@@ -1139,33 +1149,45 @@
 if (sp->key || sp->cert || sp->ca || sp->caPath || sp->cipher)
     mysql_ssl_set(conn, sp->key, sp->cert, sp->ca, sp->caPath, sp->cipher); 
 
 if (mysql_real_connect(
 	conn,
 	sp->host, /* host */
 	sp->user,	/* user name */
 	sp->password,	/* password */
 	database, /* database */
 	sp->port,	/* port */
 	sp->socket,	/* socket */
 	0)	/* flags */  == NULL)
     {
     monitorLeave();
     monitorEnterTime = oldTime;
+
+    char *extraMsg = "";
+    if (sqlIsUcscServer())
+        extraMsg = "We hate this error more than any other and may be already looking into it. You can help us by telling us "
+            "about it, "
+            "the email is genome-www@soe.ucsc.edu. We will fix it ASAP. "
+            "And even if this server is failing right now, usually, one of our other three "
+            "international mirrors is still "
+            "working. The three mirrors are genome.ucsc.edu (US), genome-euro.ucsc.edu (Germany), genome-asia.ucsc.edu "
+            "(Japan). You may not find your custom tracks and saved sessions there, but using another mirror should allow "
+            "continuing your work while we are fixing the problem. ";
+
     if (abort)
-	errAbort("Couldn't connect to database %s on %s as %s.\n%s",
-	    database, sp->host, sp->user, mysql_error(conn));
+	errAbort("Couldn't connect to database %s on %s as %s.\n%s\n%s",
+	    database, sp->host, sp->user, mysql_error(conn), extraMsg);
     else if (sqlParanoid)
 	fprintf(stderr, "Couldn't connect to database %s on %s as %s.  "
 		"mysql: %s  pid=%ld\n",
 		database, sp->host, sp->user, mysql_error(conn), (long)getpid());
     return NULL;
     }
 
 /* Make sure the db is correct in the connect, think usually happens if there
  * is a mismatch between MySQL library and code.  If this happens, please
  * figure out what is going on.  Contact markd if you need help. */
 if (((conn->db != NULL) && !sameString(database, conn->db))
    || ((conn->db == NULL) && (database != NULL)))
    errAbort("apparent mismatch between mysql.h used to compile jksql.c and libmysqlclient");
 
 sc->db=cloneString(database);