nvie/decoders

Question: Are API-friendly error messages still available?

robinchow opened this issue · 3 comments

As per here: https://nvie.com/posts/introducing-decoders/#error-messages

Thanks for the library btw, it's great!

Oh, I think I found it, I used the debrief library as follows:

import { summarize } from 'debrief'
const result = decoder(data)  // NOT guard-enclosed
if (result.isErr())
    const errVal = result.errValue()
    if (errVal)
        console.log(summarize(errVal))
nvie commented

Yes, that's one option. If you were using guard() before, you can also initialize it like so: guard(yourDecoder, { style: 'simple' }). That API isn't clearly documented (I should fix that). That's effectively the same, without requiring you to use the debrief library directly, which should be an implementation detail. (I've thought about removing the debrief library as a dependency entirely and just make it part of decoders directly, since it's pretty much the only library using it. That might happen in the future.)

Ah thanks, I will do that instead!