| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Yamlet.Error
Contents
Description
Errors with the position in the input that caused them.
Synopsis
- data Error = Error {
- location :: !Location
- message :: !String
- sourceLine :: !Text
- sourceIndex :: !Int
- path :: !Path
- data Location = Location {}
- data Path
- pathElements :: Path -> [PathElement]
- pathFromElements :: [PathElement] -> Path
- data PathElement
- = Key !Text
- | Index !Int
- | CollectionKey
- | AliasKey !Text
- prettyError :: FilePath -> Error -> String
- renderPath :: Path -> String
- errorAt :: Text -> Offset -> String -> Error
- errorsAt :: Text -> [(Offset, String)] -> [Error]
- documentErrors :: Text -> Document -> [(Offset, String)] -> [Error]
- locate :: Text -> Offset -> Location
- nodePath :: Offset -> Node -> Path
- nodePaths :: [Offset] -> Node -> [Path]
Errors
An error of the parser or the decoder.
An error from the functions of this module keeps no part of the input alive once it is in weak head normal form. Its message and its path are evaluated then, because a message often contains a slice of the input, e.g. a key, and a path comes from the syntax tree.
Constructors
| Error | |
Fields
| |
Instances
| NFData Error Source # | |||||
Defined in Yamlet.Error | |||||
| Generic Error Source # | |||||
Defined in Yamlet.Error Associated Types
| |||||
| Show Error Source # | |||||
| Eq Error Source # | |||||
| type Rep Error Source # | |||||
Defined in Yamlet.Error type Rep Error = D1 ('MetaData "Error" "Yamlet.Error" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) (C1 ('MetaCons "Error" 'PrefixI 'True) ((S1 ('MetaSel ('Just "location") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Location) :*: S1 ('MetaSel ('Just "message") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 String)) :*: (S1 ('MetaSel ('Just "sourceLine") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: (S1 ('MetaSel ('Just "sourceIndex") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "path") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Path))))) | |||||
A position in the input. Lines and columns count from 1, and a column counts characters, not bytes. Line 0 and column 0 mean that the error has no position, e.g. because it comes from a node that a program built, or from a parsed node that is decoded without its input.
Instances
| NFData Location Source # | |||||
Defined in Yamlet.Error | |||||
| Generic Location Source # | |||||
Defined in Yamlet.Error Associated Types
| |||||
| Show Location Source # | |||||
| Eq Location Source # | |||||
| type Rep Location Source # | |||||
Defined in Yamlet.Error type Rep Location = D1 ('MetaData "Location" "Yamlet.Error" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) (C1 ('MetaCons "Location" 'PrefixI 'True) (S1 ('MetaSel ('Just "offset") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Offset) :*: (S1 ('MetaSel ('Just "line") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "column") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)))) | |||||
The keys and the indices from the root of a document to a node.
The path of a node shares the path of its parent, so the paths of many errors in a deep document take memory linear in its size.
pathElements :: Path -> [PathElement] Source #
The steps of a path, from the root.
pathFromElements :: [PathElement] -> Path Source #
A path with the steps from the root.
data PathElement Source #
A step of a path into a document.
Constructors
| Key !Text | The value of a key that is a scalar, with the text of the key, e.g.
|
| Index !Int | The item of a sequence, from 0. |
| CollectionKey | The value of a key that is a collection, e.g. |
| AliasKey !Text | The value of a key that is an alias, with the name of the anchor. |
Instances
| NFData PathElement Source # | |||||
Defined in Yamlet.Error Methods rnf :: PathElement -> () | |||||
| Generic PathElement Source # | |||||
Defined in Yamlet.Error Associated Types
| |||||
| Show PathElement Source # | |||||
Defined in Yamlet.Error Methods showsPrec :: Int -> PathElement -> ShowS show :: PathElement -> String showList :: [PathElement] -> ShowS | |||||
| Eq PathElement Source # | |||||
Defined in Yamlet.Error | |||||
| type Rep PathElement Source # | |||||
Defined in Yamlet.Error type Rep PathElement = D1 ('MetaData "PathElement" "Yamlet.Error" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) ((C1 ('MetaCons "Key" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: C1 ('MetaCons "Index" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int))) :+: (C1 ('MetaCons "CollectionKey" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "AliasKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)))) | |||||
prettyError :: FilePath -> Error -> String Source #
Render an error in the format that editors recognize. The result does not end with a line break. If the line is longer than 80 characters, the excerpt shows only the 80 characters around the column. A control character other than a tab shows as its symbol, e.g. U+241B for escape, or as U+FFFD if Unicode has no symbol for it.
>>>either printErrors print (decodeText @(M.Map T.Text [[Int]]) "jobs:\n - [1]\n - 42\n")input.yaml:3:5: jobs[1]: expected a list, but got an integer | 3 | - 42 | ^
An error with no position gives only the file and the message, e.g.
input.yaml: duplicate key "a".
renderPath :: Path -> String Source #
A path in the form jobs[1].name. A key that is a collection is ?,
and a key that is an alias is its alias, e.g. *base.
A key is in double quotes, e.g. "a.b", if it:
- is empty,
- has white space, a character that cannot be printed, or one of the
characters
.[]"\, - starts with
?or*.
In the quotes, a character that cannot be printed has an escape as in
YAML, e.g. "a\nb".
>>>renderPath (pathFromElements [Key "jobs", Index 1, Key "name"])"jobs[1].name"
>>>renderPath (pathFromElements [Key "a.b", Key ""])"\"a.b\".\"\""
Construction
errorAt :: Text -> Offset -> String -> Error Source #
Create an error at the given offset of the input.
errorsAt :: Text -> [(Offset, String)] -> [Error] Source #
Create errors at the given offsets of the input, in the order of the list. One scan of the input locates all of them, and the errors on one line share the copy of the line.
documentErrors :: Text -> Document -> [(Offset, String)] -> [Error] Source #
Create errors at the given offsets of a document, with their paths, in the
order of the list. The text is the input of the document, e.g. for the
offsets of Located values.
locate :: Text -> Offset -> Location Source #
Compute the line and the column of an offset. The byte order marks at the
start of a line are not columns, because they are not content. For
noOffset or an offset beyond the end of the input, the line and the
column are 0.