Too many arguments to return have (error) want ()

I’m using validation library which is hosted on Github…

Inside main function i have written this code to validate library

schema, err := jsonschema.Compile(“schemas/purchaseOrder.json”)
if err != nil {
return err
}
f, err := os.Open(“purchaseOrder.json”)
if err != nil {
return err
}
defer f.Close()
if err = schema.Validate(f); err != nil {
return err
}

If i try to return the occurring validation exceptions means its throwing exception like this

.\validation.go:12:2: too many arguments to return
have (error)
want ()
.\validation.go:16:3: too many arguments to return
have (error)
want ()
.\validation.go:20:3: too many arguments to return
have (error)
want ()

for each error return its throwing exception
but i want to use return (return err) only i don’t want to use panic
I’m new this programming
Any suggestions to sort this issue

Is validation.go your file or is it part of the library? Which are the lies 12, 16 and 20?

Its just file

You can’t return an error from main. Log it and exit.

This has nothing to do with the JSON library.

I can use it but if want to print the exception means how to do it?

You can use fmt.Println() or its friends.

1 Like

I usually use another function to do real work. Example:

https://play.golang.org/p/HIHuEjBkL83

Good luck!

Jeff Kayser

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.