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

Error() prints too many end-lines #44

Closed
manucorporat opened this issue May 22, 2015 · 7 comments
Closed

Error() prints too many end-lines #44

manucorporat opened this issue May 22, 2015 · 7 comments
Assignees
Milestone

Comments

@manucorporat
Copy link

Since the errors reported by validator will be likely sent through JSON or printed in a log:
I would recommend to remove most of the end-lines:

Struct: Field validation for "Id" failed on the "required" tag

instead of:

Struct:
Field validation for "Id" failed on the "required" tag


@deankarn
Copy link
Contributor

I agree this makes sense for logging, I will remove the line breaks.

I do however feel the need to point out that, like the documentation states, these errors are intended for debugging and not production error messages.

For example the end user would probably want to see the error

Email is required

Instead of

Field validation for "Email" failed on the "required" tag

@deankarn deankarn self-assigned this May 22, 2015
@deankarn deankarn added this to the v5 Additions milestone May 22, 2015
@deankarn deankarn added the new label May 22, 2015
@manucorporat
Copy link
Author

I am working in a complete integration with gin, this is a automatic generated error JSON.

{  
   "error":"Struct:JSON\nField validation for \"Title\" failed on the \"required\" tag\nField validation for \"Description\" failed on the \"required\" tag\nField validation for \"Body\" failed on the \"required\" tag\n\n\n",
   "fields":[  
      "title",
      "description",
      "body"
   ],
   "message":"title, description and body are required."
}

what do you think?
see! there are many end-lines in the error message.

type JSON struct {
    Title       string `binding:"required"`
    Description string `binding:"required"`
    Body        string `binding:"required"`
}

func main() {
    router := gin.Default()
    router.Use(gin.ErrorLogger())
    router.POST("/", func(c *gin.Context) {
        var json JSON
        if c.BindJSON(&json) == nil {
            // read json safely
        }
    })
    router.Run(":8080")
}

@deankarn
Copy link
Contributor

I am working on this and a few other things and should be completed within the next few hours.

the fix removes the extra 3 \n's

@manucorporat
Copy link
Author

@joeybloggs nice!
check out my work in progress, maybe we should join efforts (but for now... I am going to sleep ;) )
https://github.com/gin-gonic/validator/commit/474180a2dd22572102897e4db08c6fddbac5c767
gin-gonic/gin@784d734

@manucorporat
Copy link
Author

offtopic: I love the new v5 API. nice work!

@manucorporat manucorporat changed the title Error() prints to many end-lines Error() prints too many end-lines May 23, 2015
@deankarn
Copy link
Contributor

thanks @manucorporat

I'll take a look

This was referenced May 23, 2015
@manucorporat
Copy link
Author

nice!

@deankarn deankarn added the bug label Jun 5, 2015
fairyhunter13 added a commit to fairyhunter13/validator that referenced this issue Jul 12, 2020
fairyhunter13 added a commit to fairyhunter13/validator that referenced this issue Jul 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants