Skip to content

Commit

Permalink
added some error handling
Browse files Browse the repository at this point in the history
should fix a rare case of "could not read getAttribute of null"
  • Loading branch information
nleanba committed Mar 4, 2024
1 parent c11763f commit d5db0ab
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/gg2rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export function gg2rdf(inputPath: string, outputPath: string, log: (msg: string)

// this is the <document> surrounding everything. doc != document
const doc = document.querySelector("document") as Element;
if (!doc) {
log(`Error: missing <document> in ${inputPath}.`);
output("# Could not create RDF due to missing <document>");
}
const id = doc.getAttribute("docId");
log(`starting gg2rdf on document id: ${id}`);

Expand Down Expand Up @@ -255,7 +259,10 @@ export function gg2rdf(inputPath: string, outputPath: string, log: (msg: string)
const cTaxon = e.tagName === "taxonomicName"
? e
: e.querySelector("taxonomicName");
addTaxonConceptCitation(t, taxon, cTaxon);
if (cTaxon) addTaxonConceptCitation(t, taxon, cTaxon);
else {
log(`${e.tagName} found without taxonomicName`);
}
});

// makeCitedMaterial returns the identifier
Expand Down Expand Up @@ -1079,13 +1086,13 @@ export function gg2rdf(inputPath: string, outputPath: string, log: (msg: string)
// to keep author ordering (after xslt replaced):
// const docAuthor = STR(doc.getAttribute("docAuthor"))

const mods = document.getElementsByTagName(
"MODSname",
);
const mods = document.querySelectorAll("MODSname") as Element[];
const modsAuthor = STR(
mods.filter((m) =>
m.querySelector("MODSroleTerm").innerText.match(/author/i)
).map((m) => (m.querySelector("MODSnamePart").innerText as string).trim())
(m.querySelector("MODSroleTerm")?.innerText as string)?.match(/author/i)
).map((m) =>
(m.querySelector("MODSnamePart")?.innerText as string).trim()
)
.join("; "),
);

Expand Down

0 comments on commit d5db0ab

Please sign in to comment.