Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unmarshalFile how can i skip line that fail #268

Open
danielzed opened this issue Dec 13, 2023 · 2 comments
Open

unmarshalFile how can i skip line that fail #268

danielzed opened this issue Dec 13, 2023 · 2 comments

Comments

@danielzed
Copy link

help, unmarshalFile how can i skip line that fail.
i suppose skip line that produce error is not supported.
withErrorHandler can know which line is fail,but cannot skip that line
or i can read each line and call UnmarshalBytes multiple times

want to know which way is suggested. thanks

@lacombar
Copy link

lacombar commented Dec 22, 2023

Having the exact same problem, my data file contains junk lines, and it would be nice to have a way to skip these...

@lacombar
Copy link

lacombar commented Dec 22, 2023

Found it... Expected syntax is:

import (
        "encoding/csv"
)
[...]
        errHandler := func(err *csv.ParseError) bool {
                fmt.Println(err)                                                                                                                           
                return true                                                                                                                                
        }                                                                                                                                                  
          
        err = gocsv.UnmarshalFileWithErrorHandler(file, errHandler, &entries)                                                                              
        if err != nil { // Load clients from file                                                                                                          
                panic(err)                                                                                                                                 
        }

However I might extend this to tweak the behavior of the error handler, ie. I might either want to ignore the error (current behavior if true is returned) or skip the row altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants