52432895f426bc722014061bc7a79eb1ca8b025d max Sun Sep 6 06:55:18 2026 -0700 getTrackReferences: abort with an error on stderr when the NCBI full-text link cannot be fetched, instead of printing the error onto stdout where it ends up in the middle of the generated references. refs #38265 diff --git src/hg/encode/getTrackReferences/getTrackReferences src/hg/encode/getTrackReferences/getTrackReferences index 0896cc5219d..497f037b067 100755 --- src/hg/encode/getTrackReferences/getTrackReferences +++ src/hg/encode/getTrackReferences/getTrackReferences @@ -142,33 +142,36 @@ break else: #n = re.search('<div class="icons"></div>', doc) # another possible detection of failed portlet p = re.search('Default output of portlet NCBIPageSection', doc) if p is None: break except: try: m = re.search(r'<div class="full-text-links-list">\s*<a\s+(class="[^"]*"\s+)?href="(.+)"', fetch.text) if m: if m.group(2): # Rhetorical: how can m match without m.group(1) being defined for this regex? Anyway .... infoDict['url'] = m.group(2).replace("&", "&").replace(" ", "%20").replace("///","//") break except: - print("Failed to fetch complete links from NCBI after 10 tries. Try again later or just use the PubMed paper link.") + # this try failed, fall through to the next one + pass else: - print("Failed to fetch complete links from NCBI after 10 tries. Try again later or just use the PubMed paper link.") + # never print this on stdout: it would end up in the middle of the references + sys.exit("error: failed to fetch the full-text link from NCBI after 10 tries. Try again " + "later, or use the PubMed link %s as the reference URL." % origUrl) htmlLines = list() htmlLines.append("<p>") htmlLines.append("%s" % authStr) if (not plain): htmlLines.append("<a href=\"%s\" target=\"_blank\">" % htmlEscape(infoDict['url'])) htmlLines.append("%s</a>." % htmlEscape(title)) htmlLines.append("<em>%s</em>. %s" % (htmlEscape(journal), dateStr)) else: htmlLines.append("<a href=\"%s\" target=\"_blank\">" % infoDict['url']) htmlLines.append("%s</a>." % title) htmlLines.append("<em>%s</em>. %s" % (journal, dateStr)) htmlLines.append("%s" % idStr) htmlLines.append("</p>") if plain: