Skip to content
Snippets Groups Projects
Select Git revision
  • 63b0c056558ef0f3346f6e704a3bb6712e763e71
  • main default protected
  • 1-mage-run-does-not-stop-containers
  • v0.26.0
  • v0.25.0
  • v0.24.0
  • v0.23.0
  • v0.22.0
  • v0.21.0
  • v0.20.0
  • v0.19.0
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.0
  • v0.14.0
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
23 results

debug.go

Blame
  • error.go 6.83 KiB
    package errors
    
    import (
    	"fmt"
    	"net/http"
    	"path"
    	"strconv"
    	"strings"
    )
    
    // CustomError implements the following interfaces:
    //
    //	error
    //	github.com/pkg/errors: Cause
    type CustomError struct {
    	code    int
    	message string
    	caller  Caller
    	cause   error
    }
    
    // implement interface error:
    func (err CustomError) Error() string {
    	return err.Formatted(FormattingOptions{Causes: false})
    }
    
    func Is(e1, e2 error) bool {
    	if e1WithIs, ok := e1.(ErrorWithIs); ok {
    		return e1WithIs.Is(e2)
    	}
    	return e1.Error() == e2.Error()
    }
    
    // Is() compares the message string of this or any cause to match the specified error message
    func (err CustomError) Is(specificError error) bool {
    	if err.message == specificError.Error() {
    		return true
    	}
    	if err.cause != nil {
    		if causeWithIs, ok := err.cause.(ErrorWithIs); ok {
    			return causeWithIs.Is(specificError)
    		}
    	}
    	return false
    }
    
    // implement github.com/pkg/errors: Cause
    func (err CustomError) Cause() error {
    	return err.cause
    }
    
    func HTTPCode(err error) int {
    	if errWithCode, ok := err.(ErrorWithCause); ok {
    		return errWithCode.Code()
    	}
    	return 0
    }
    
    func (err CustomError) Code() int {
    	// find http error code - returning the smallest code in the stack of causes (excluding code==0)
    	code := err.code
    	if err.cause != nil {
    		if causeWithCode, ok := err.cause.(ErrorWithCause); ok {
    			causeCode := causeWithCode.Code()
    			if code == 0 || (causeCode != 0 && causeCode < code) {
    				code = causeCode
    			}
    		}
    	}
    	return code