npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pavelkucera/io-ts-structural-error-reporter

v0.1.1

Published

Report io-ts errors using the structure of the underlying validators

Readme

Structural io-ts Error Reporter

Library to give you structural error reports from validation errors created by io-ts. The library is motivated by a desire to use io-ts to validate a REST API's JSON input and return errors in an approachable format.

Installation

npm install --save-exact @pavelkucera/io-ts-structural-error-reporter

Usage

Use StructuralErrorReporter.report to convert result of Type.decode into errors copying the underlying Type structure. The type of the report function is:

import { Either } from 'fp-ts/lib/Either'
import * as t from 'io-ts'

type Reporter = (validation: t.Validation<any>) => Either<InternalError, ErrorReport>

type ErrorReportRecord = {
  [key: string]: ErrorReport
}

type ErrorReport =
  | string
  | ErrorReportRecord

The reporter is designed not to throw any errors during runtime, which is why the return value is of type Either. In general, an error/Left result means that a "this should never happen" error happened in library or on the boundary between the library and io-ts. In such a case, the only course of action should be aborting (and reporting an issue).

The reporter is supposed to run only when a validation fails, and thus the reporter reports an error when validation succeeds. Now on to the example that you are waiting for!

Example

import { InternalError, StructuralErrorReporter } from '@pavelkucera/io-ts-structural-error-reporter'
import * as Either from 'fp-ts/lib/Either'
import * as t from 'io-ts'

const type = t.type({
  string: t.string,
  nested: t.type({
    property: t.string,
  })
})

const decodedValue = type.decode({
  string: 42, // should be string
  nested: {
    property: 42, // should be string
  }
});

const errorReport = StructuralErrorReporter.report(decodedValue);

// Use some of the Either functionality to unwrap the result.
const structrualErrorReport = Either.getOrElse<InternalError, ErrorReport>(
  _error => { throw new Error('Panic') }
)(errorReport)

console.log(structrualErrorReport);
// prints:
// {
//   string: 'Expecting "string".',
//   nested: {
//     property: 'Expecting "string".',
//   },
// }

Error Messages

If the codec defines its own error message, the library will use that error message. Otherwise, a default error message will be used. The default error message is in format:

Expecting: "<name of the codec>".