97a48c4a38b1032011acc92c711dd5ed3f258620
chmalee
  Thu Jun 12 11:10:25 2025 -0700
If we didn't find the requested item in the genePred, do not continue as if we had found it, refs #35799

diff --git src/hg/hgApi/hgApi.c src/hg/hgApi/hgApi.c
index bab23310ca7..04e72eea7f0 100644
--- src/hg/hgApi/hgApi.c
+++ src/hg/hgApi/hgApi.c
@@ -216,39 +216,42 @@
         {
         // TODO: what bigBed types can we even support? bigBed12 at a minimum for the blocks?
         // bigPsl should work maybe?
         // for now just support genePred and bigGenePred
         char *fileName = bbiNameFromSettingOrTable(tdb, conn, tdb->table);
         struct bbiFile *bbi = bigBedFileOpenAlias(fileName, chromAliasFindAliases);
         int fieldIx;
         struct bptFile *bpt = bigBedOpenExtraIndex(bbi, "name", &fieldIx);
         struct lm *lm = lmInit(0);
         struct bigBedInterval *bbList = bigBedNameQuery(bbi, bpt, fieldIx, name, lm);
         if (bbList)
             gp = (struct genePred *)genePredFromBigGenePred(chrom, bbList);
         }
     if (!gp)
         dyStringPrintf(output, "{\"error\": \"Couldn't find item: %s\"}", name);
+    else
+        {
         boolean found; int start, end;
         if (sameString(cmd, "codonToPos"))
             found = codonToPos(gp, num, &start, &end);
         else
             found = exonToPos(gp, num, &start, &end);
         if (found)
             dyStringPrintf(output, "{\"pos\": \"%s:%d-%d\"}", gp->chrom, start + 1, end);
         else
             dyStringPrintf(output, "{\"error\": \"%d is an invalid %s for this gene\"}", num, sameString(cmd, "codonToPos") ? "codon" : "exon");
+        }
     hFreeConn(&conn);
     }
 else
     {
     warn("unknown cmd: %s",cmd);
     errAbort("Unsupported 'cmd' parameter");
     }
 
 apiOut(dyStringContents(output), jsonp);
 cgiExitTime("hgApi", enteredMainTime);
 }
 
 /* Null terminated list of CGI Variables we don't want to save
  * permanently. */
 char *excludeVars[] = {"fileSearch", "var", "showShortLabel", "showLongLabel", "track", "table", "name", "chrom", "cmd", "num",  NULL,};