config-schema-1.3.0.0: Schema definitions for the config-value package

Copyright | (c) Eric Mertens 2017
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Config.Schema.Load

Contents

- Errors

Description

This module automates the extraction of a decoded value from a configuration value according to a specification as built using Config.Schema.Spec.

Synopsis

- loadValue :: ValueSpec a -> Value p -> Either (ValueSpecMismatch p) a
- loadValueFromFile :: ValueSpec a -> FilePath -> IO a
- data ValueSpecMismatch p = ValueSpecMismatch p Text (NonEmpty (PrimMismatch p))
- data PrimMismatch p = PrimMismatch Text (Problem p)
- data Problem p
  - = MissingSection Text
  - | UnusedSections (NonEmpty Text)
  - | SubkeyProblem Text (ValueSpecMismatch p)
  - | ListElementProblem Int (ValueSpecMismatch p)
  - | NestedProblem (ValueSpecMismatch p)
  - | TypeMismatch
  - | CustomProblem Text
  - | WrongExact

# Documentation

loadValue Source #

Arguments

:: ValueSpec a | specification
-> Value p | value
-> Either (ValueSpecMismatch p) a | errors or decoded value

Match a `Value` against a `ValueSpec` and return either the interpretation of that value or the list of errors encountered.

loadValueFromFile Source #

Arguments

:: ValueSpec a | specification
-> FilePath | filename
-> IO a |

Read a configuration file, parse it, and validate it according to the given specification.

Throws `IOError`, `ParseError`, or `ValueSpecMismatch`

# Errors

data ValueSpecMismatch p Source #

Newtype wrapper for schema load errors.

Since: 1.2.0.0

Constructors

ValueSpecMismatch p Text (NonEmpty (PrimMismatch p)) | Problem value and list of specification failures

#### Instances

Instances details

ErrorAnnotation p => Exception (ValueSpecMismatch p) Source # | `displayException` implemented with `prettyValueSpecMismatch` and `simplifyValueSpecMismatch`. Since: 1.2.0.0
Instance details Defined in Config.Schema.Load.Error Methods toException :: ValueSpecMismatch p -> SomeException Source # fromException :: SomeException -> Maybe (ValueSpecMismatch p) Source # displayException :: ValueSpecMismatch p -> String Source # backtraceDesired :: ValueSpecMismatch p -> Bool Source #
Show p => Show (ValueSpecMismatch p) Source # |
Instance details Defined in Config.Schema.Load.Error Methods showsPrec :: Int -> ValueSpecMismatch p -> ShowS Source # show :: ValueSpecMismatch p -> String Source # showList :: [ValueSpecMismatch p] -> ShowS Source #

data PrimMismatch p Source #

Type for errors that can be encountered while decoding a value according to a specification. The error includes a key path indicating where in the configuration file the error occurred.

Since: 1.2.0.0

Constructors

PrimMismatch Text (Problem p) | spec description and problem

#### Instances

Instances details

Show p => Show (PrimMismatch p) Source # |
Instance details Defined in Config.Schema.Load.Error Methods showsPrec :: Int -> PrimMismatch p -> ShowS Source # show :: PrimMismatch p -> String Source # showList :: [PrimMismatch p] -> ShowS Source #

data Problem p Source #

Problems that can be encountered when matching a `Value` against a `ValueSpec`.

Since: 1.2.0.0

Constructors

MissingSection Text | missing section name
UnusedSections (NonEmpty Text) | unused section names
SubkeyProblem Text (ValueSpecMismatch p) | nested error in given section
ListElementProblem Int (ValueSpecMismatch p) | nested error in given list element
NestedProblem (ValueSpecMismatch p) | generic nested error
TypeMismatch | value and spec type mismatch
CustomProblem Text | custom spec error message
WrongExact | values didn't match

#### Instances

Instances details

Show p => Show (Problem p) Source # |
Instance details Defined in Config.Schema.Load.Error Methods showsPrec :: Int -> Problem p -> ShowS Source # show :: Problem p -> String Source # showList :: [Problem p] -> ShowS Source #