@@ -155,25 +155,39 @@ func (e *MissingColumnsError) Error() string {
155155 return b .String ()
156156}
157157
158- // decodeError provides context to decoding errors if available.
158+ // DecodeError provides context to decoding errors if available.
159159//
160160// The caller should use errors.As in order to fetch the underlying error if
161161// needed.
162- type decodeError struct {
163- Field string
164- Line int
162+ //
163+ // Some of the DecodeError's fields are only populated if the Reader supports
164+ // PosField method. Specifically Line and Column. FieldPos is available in
165+ // csv.Reader since Go1.17.
166+ type DecodeError struct {
167+ // Field describes the struct's tag or field name on which the error happened.
168+ Field string
169+
170+ // Line is 1-indexed line number taken from FieldPost method. It is only
171+ // available if the used Reader supports FieldPos method.
172+ Line int
173+
174+ // Column is 1-indexed column index taken from FieldPost method. It is only
175+ // available if the used Reader supports FieldPos method.
165176 Column int
166- Err error
177+
178+ // Error is the actual error that was returned while attempting to decode
179+ // a field.
180+ Err error
167181}
168182
169- func (e * decodeError ) Error () string {
183+ func (e * DecodeError ) Error () string {
170184 if e .Line > 0 && e .Column > 0 {
171185 // Lines and Columns are 1-indexed so this check is fine.
172186 return fmt .Sprintf ("%s: field %q line %d column %d" , e .Err , e .Field , e .Line , e .Column )
173187 }
174188 return fmt .Sprintf ("%s: field %q" , e .Err , e .Field )
175189}
176190
177- func (e * decodeError ) Unwrap () error {
191+ func (e * DecodeError ) Unwrap () error {
178192 return e .Err
179193}
0 commit comments