Standard library / encoding/csv

encoding/csv.ParseError.Unwrap()

Return the underlying CSV parsing error so errors.Is can identify field-count and quote errors. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
func (e *ParseError) Unwrap() error

Return Value

error

Underlying error.

Working Example

Example Snippetgo
package main
import (  "encoding/csv"  "errors"  "fmt"  "strings")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  r := csv.NewReader(strings.NewReader("a,b\nc\n"))  _, e := r.Read()  must(e)  _, e = r.Read()  var p *csv.ParseError  fmt.Println(errors.As(e, &p), p.Unwrap() == csv.ErrFieldCount)}
Go Reference