023255de913dda73eeceee882e1b5f824c94f34f
jcasper
  Tue Apr 18 10:52:42 2023 -0700
Need to catch errors on opening a hic file with Straw, because the
magic string check can also generate an exception.  refs #31071

diff --git src/hg/lib/hic.c src/hg/lib/hic.c
index 8021786..6dfd4a5 100644
--- src/hg/lib/hic.c
+++ src/hg/lib/hic.c
@@ -26,32 +26,35 @@
     if (startsWith("CHR", workingName))
         offset = 3;
     safencpy(mangledUcscName, size, workingName+offset, strlen(workingName+offset));
 }
 
 
 char *hicLoadHeader(char *filename, struct hicMeta **header, char *ucscAssembly)
 /* Create a hicMeta structure for the supplied Hi-C file.  If
  * the return value is non-NULL, it points to a string containing
  * an error message that explains why the retrieval failed. */
 {
 char *genome;
 char **chromosomes, **bpResolutions, **attributes;
 int *chromSizes, nChroms, nBpRes, nAttributes;
 
-Straw *newStraw = cStrawOpen(filename);
-char *errMsg = cStrawHeader(newStraw, &genome, &chromosomes, &chromSizes, &nChroms, &bpResolutions, &nBpRes, NULL, NULL, &attributes, &nAttributes);
+Straw *newStraw = NULL;
+char *errMsg = cStrawOpen(filename, &newStraw);
+if (errMsg != NULL)
+    return errMsg;
+errMsg = cStrawHeader(newStraw, &genome, &chromosomes, &chromSizes, &nChroms, &bpResolutions, &nBpRes, NULL, NULL, &attributes, &nAttributes);
 if (errMsg != NULL)
     return errMsg;
 
 struct hicMeta *newMeta = NULL;
 AllocVar(newMeta);
 newMeta->strawObj = newStraw;
 newMeta->fileAssembly = genome;
 newMeta->nRes = nBpRes;
 newMeta->resolutions = bpResolutions;
 newMeta->nChroms = nChroms;
 newMeta->chromNames = chromosomes;
 newMeta->chromSizes = chromSizes;
 newMeta->ucscToAlias = NULL;
 newMeta->ucscAssembly = cloneString(ucscAssembly);
 newMeta->filename = cloneString(filename);