github.com/octohelm/storage@v0.0.0-20240516030302-1ac2cc1ea347/pkg/dberr/util.go (about)

     1  package dberr
     2  
     3  func UnwrapAll(err error) error {
     4  	for {
     5  		if cause := UnwrapOnce(err); cause != nil {
     6  			err = cause
     7  			continue
     8  		}
     9  		break
    10  	}
    11  	return err
    12  }
    13  
    14  func UnwrapOnce(err error) (cause error) {
    15  	switch e := err.(type) {
    16  	case interface{ Cause() error }:
    17  		return e.Cause()
    18  	case interface{ Unwrap() error }:
    19  		return e.Unwrap()
    20  	}
    21  	return nil
    22  }