Thanks to visit codestin.com
Credit goes to github.com

Skip to content

implement ".Unwrap() error" on Error type #2525

@LeGEC

Description

@LeGEC

Description

The 'Error' type defined in errors.go does not implement ".Unwrap() error", which prevents the usage of "errors.Is()" and "errors.As()"

How to reproduce

package main

import (
	"github.com/gin-gonic/gin"
)

type TestStrErr string

func (e TestStrErr) Error() string { return string(e) }

func main() {
	testErr := TestStrErr("some error")

	err := &gin.Error{Err: testErr}

	if errors.Is(err, testErr) {
	    fmt.Println("match with testErr ok")
	}
	
	var unwrap TestStrErr
	if errors.As(err, &unwrap) {
	    fmt.Println("succesfully unwrapped as a TestStrErr")
	}
}

Expectations

output :

match with testErr ok
succesfully unwrapped as a TestStrErr

Actual result

no output

Environment

  • go version: go version go1.14.2 linux/amd64
  • gin version (or commit ref): 540b1ef
  • operating system: linux

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