io-ts-reporters icon indicating copy to clipboard operation
io-ts-reporters copied to clipboard

Is it possible to report Either<DecodeError, A>

Open aldex32 opened this issue 2 years ago • 1 comments

Hello, I am using [email protected] and [email protected], but I cannot report an error for decode responses such as Either<DecodeError, A>. This is an example where I want to use the report instead of a raw error.

import * as D from 'io-ts/Decoder';
import { pipe } from 'fp-ts/function';
import { fold } from 'fp-ts/Either';

export function decode<A>(input: unknown, decoder: D.Decoder<unknown, A>): A {
    return pipe(
        decoder.decode(input),
        fold(
            (errors) => {
                throw new Error(JSON.stringify(errors)); // Here I want to use the reporter.
            },
            (value: A) => value,
        ),
    );
}

Are you planning to support the D.DecodeError for reporting?

aldex32 avatar Mar 31 '22 12:03 aldex32

Hi, I hadn't used io-ts/Decoder yet, only io-ts/index, so I did not come across the problem. And yes, this should be supported.

gillchristian avatar Mar 31 '22 15:03 gillchristian