06348905fb820c091e8d1c144c4fb39089a9a22e
galt
  Tue Jul 31 16:55:13 2012 -0700
hgc - cleaned up code with simpler, more reliable approach.
diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index d1c5b70..388bc31 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -1447,36 +1447,38 @@
 vfprintf(stderr, format, argscp);
 va_end(argscp);
 putc('\n', stderr);
 fflush(stderr);
 }
 
 void cartWarnCatcher(void (*doMiddle)(struct cart *cart), struct cart *cart, WarnHandler warner)
 /* Wrap error and warning handlers around doMiddle. */
 {
 pushWarnHandler(warner);
 cartErrorCatcher(doMiddle, cart);
 popWarnHandler();
 }
 
 static boolean inWeb = FALSE;
+static boolean didCartHtmlStart = FALSE;
 
 void cartHtmlStart(char *title)
 /* Write HTML header and put in normal error handler. */
 {
 pushWarnHandler(htmlVaWarn);
 htmStart(stdout, title);
+didCartHtmlStart = TRUE;
 }
 
 void cartVaWebStart(struct cart *cart, char *db, char *format, va_list args)
 /* Print out pretty wrapper around things when working
  * from cart. */
 {
 pushWarnHandler(htmlVaWarn);
 webStartWrapper(cart, db, format, args, FALSE, FALSE);
 inWeb = TRUE;
 }
 
 void cartWebStart(struct cart *cart, char *db, char *format, ...)
 /* Print out pretty wrapper around things when working
  * from cart. */
 {
@@ -1505,32 +1507,34 @@
 
 void cartFooter(void)
 /* Write out HTML footer, possibly with googleAnalytics too */
 {
 #ifndef GBROWSE
 googleAnalytics();	/* can't do this in htmlEnd	*/
 #endif /* GBROWSE */
 htmlEnd();		/* because it is in a higher library */
 }
 
 void cartHtmlEnd()
 /* Write out HTML footer and get rid or error handler. */
 {
 if (inWeb)
     webEnd();	/*	this does googleAnalytics for a lot of CGIs	*/
-else
+else if (didCartHtmlStart)
     cartFooter();
+else
+    return;
 popWarnHandler();
 }
 
 void setThemeFromCart(struct cart *cart) 
 /* If 'theme' variable is set in cart: overwrite background with the one from
  * defined for this theme Also set the "styleTheme", with additional styles
  * that can overwrite the main style settings */
 {
 // Get theme from cart and use it to get background file from config;
 // format is browser.theme.<name>=<stylesheet>[,<background>]
 
 char *cartTheme = cartOptionalString(cart, "theme");
 
 // XXXX which setting should take precedence? Currently browser.theme does.