Skip to content

Commit

Permalink
Make lexicon validation DEV-only
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Nov 1, 2023
1 parent 8637c36 commit 404e3f5
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/lexicon/src/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ export class Lexicons {
* Add a lexicon doc.
*/
add(doc: unknown): void {
try {
lexiconDoc.parse(doc)
} catch (e) {
if (e instanceof ZodError) {
throw new LexiconDocMalformedError(
`Failed to parse schema definition ${
(doc as Record<string, string>).id
}`,
doc,
e.issues,
)
} else {
throw e
if (process.env.NODE_ENV !== 'production') {
try {
lexiconDoc.parse(doc)
} catch (e) {
if (e instanceof ZodError) {
throw new LexiconDocMalformedError(
`Failed to parse schema definition ${
(doc as Record<string, string>).id
}`,
doc,
e.issues,
)
} else {
throw e
}
}
}
const validatedDoc = doc as LexiconDoc
Expand Down

0 comments on commit 404e3f5

Please sign in to comment.