Skip to content

Commit

Permalink
Unexpected DB format shouldn't be fatal (fixes #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
haukex committed Jul 14, 2024
1 parent 879b106 commit ef07a9a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,17 @@ window.addEventListener('DOMContentLoaded', async () => {
scoredMatches.slice(0, MAX_RESULTS).forEach((scoredMatch, mi) => {
// split the dictionary lines into "German :: English"
const trans = scoredMatch[0].split(/::/)
if (trans.length!=2)
throw new Error(`unexpected database format on line "${scoredMatch[0]}"`)
if (trans.length!=2) {
console.error('unexpected database format on line', scoredMatch[0])
return
}
// split each entry on "|"s, should have the same number of entries on each side
const des = (trans[0] as string).split(/\|/)
const ens = (trans[1] as string).split(/\|/)
if (des.length!=ens.length)
throw new Error(`unexpected database format on line "${scoredMatch[0]}"`)
if (des.length!=ens.length) {
console.error('unexpected database format on line', scoredMatch[0])
return
}
// generate the HTML for each result
des.map((de, i) => {
const en = ens[i] as string
Expand Down

0 comments on commit ef07a9a

Please sign in to comment.