Skip to content

Commit 2a2437c

Browse files
maxlathEdJoPaTo
andcommitted
parseSnak: refactor error handling
Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de>
1 parent b1f388e commit 2a2437c

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/helpers/parse_snak.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,12 @@ export function parseSnak (datatype: DataType | void, datavalue: SnakValue, opti
112112
// @ts-expect-error Known case of missing datatype: form.claims, sense.claims, mediainfo.statements
113113
datatype = datatype || datavalue.type
114114

115-
try {
116-
// Known case requiring normalization
117-
// - legacy "musical notation" datatype
118-
// - mediainfo won't have datatype="globe-coordinate", but datavalue.type="globecoordinate"
119-
const parser = normalizedParsers[normalizeDatatype(datatype)]
120-
return parser(datavalue, options)
121-
} catch (err) {
122-
if (err.message === 'parsers[datatype] is not a function') {
123-
err.message = `${datatype} claim parser isn't implemented
124-
Please report to https://github.com/maxlath/wikibase-sdk/issues`
125-
}
126-
throw err
115+
// Known case requiring normalization
116+
// - legacy "musical notation" datatype
117+
// - mediainfo won't have datatype="globe-coordinate", but datavalue.type="globecoordinate"
118+
const parser = normalizedParsers[normalizeDatatype(datatype)]
119+
if (!parser) {
120+
throw new Error(`${normalizeDatatype(datatype)} claim parser isn't implemented. Please report to https://github.com/maxlath/wikibase-sdk/issues`)
127121
}
122+
return parser(datavalue, options)
128123
}

0 commit comments

Comments
 (0)