Skip to content

gin.Error does not implement the error interface #630

@tevjef

Description

@tevjef

I was attempting to use the exported gin.Errortype in func (c *Context) Error(err error) *Error but it fails on compilation.

func someFunc(c *gin.Context) {
  if u, err := SomeOp(); err != nil {
    c.Error(gin.Error{err, gin.ErrorTypePublic, c.Request.URL.String()})
  }
}

Here's the compilation error :
cannot use gin.Error literal (type gin.Error) as type error in argument to c.Error: gin.Error does not implement error (Error method has pointer receiver)

If seems like the inteface was improperly implemented here as the reviecer type should not have be an *Error.

This should fix it.

// Implements the error interface
func (msg Error) Error() string {
    return msg.Err.Error()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions