9abe0c1c7159998b51597ba166ee7a0e56fd48ca jcasper Wed Apr 15 12:17:09 2026 -0700 Adding some error handling for faceted composites with missing or invalid primaryKey settings, refs #36320 diff --git src/hg/js/facetedComposite.js src/hg/js/facetedComposite.js index e5fbb8da62a..912f6710d5f 100644 --- src/hg/js/facetedComposite.js +++ src/hg/js/facetedComposite.js @@ -728,30 +728,34 @@ }) : fetch(fetchUrl, { method: "GET", headers: { "Content-Type": "application/x-www-form-urlencoded" }, }); req.then(response => { if (!response.ok) { // a 404 will look like plain text throw new Error(`HTTP Status: ${response.status}`); } return response.text(); }) .then(tsvText => { // metadata table is a TSV file to parse loadOptional(colorSettingsUrl, hgsid, track).then(colorMap => { const rows = tsvText.trim().split("\n"); const colNames = rows[0].split("\t"); + if (!primaryKey) + throw new Error("trackDb setting 'primaryKey' is missing"); + if (!colNames.includes(primaryKey)) + throw new Error(`primaryKey '${primaryKey}' not found in metadata columns`); const metadata = rows.slice(1).map(row => { const values = row.split("\t"); const obj = {}; colNames.forEach((attrib, i) => { obj[attrib] = values[i]; }); return obj; }); const rowToIdx = Object.fromEntries( metadata.map((row, i) => [row[primaryKey], i]) ); colorMap = isValidColorMap(colorMap) ? colorMap : null; const freshData = { metadata, rowToIdx, colNames, colorMap }; initAll(freshData); }); })