diff --git a/implementations/javascript/packages/schema/src/compiler/genunconverter.ts b/implementations/javascript/packages/schema/src/compiler/genunconverter.ts index d9431be..3cbba75 100644 --- a/implementations/javascript/packages/schema/src/compiler/genunconverter.ts +++ b/implementations/javascript/packages/schema/src/compiler/genunconverter.ts @@ -58,7 +58,14 @@ function unconverterForAlternative( } return (cs.length === 1) ? cs[0] : seq(`_.merge`, parens(`(a, b) => (a === b) ? a : void 0`, ... cs)); } else { - return unconverterFor(ctx, a.value, src, t); + try { + return unconverterFor(ctx, a.value, src, t); + } catch (e) { + if (e instanceof InsufficientInformationError) { + throw new Error(`Cannot produce unconverter for ${name}: ${e.message}`); + } + throw e; + } } } @@ -82,7 +89,7 @@ function unconverterFor(ctx: FunctionContext, p: M.Pattern, src: string, t: Simp switch (p._variant) { case 'SimplePattern': return ((p: M.SimplePattern) => { - if (p._variant !== 'lit' && t.kind === 'record') { + if (p._variant !== 'lit' && (t.kind === 'record' || t.kind === 'unit')) { throw new InsufficientInformationError(`A Cannot produce unconverter TODO ${src} ${formatItems([renderType(t)])}`); } switch (p._variant) {