github.com/grafana/pyroscope@v1.18.0/pkg/symbolizer/errors.go (about)

     1  package symbolizer
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  type invalidBuildIDError struct {
     9  	buildID string
    10  }
    11  
    12  func (e invalidBuildIDError) Error() string {
    13  	return fmt.Sprintf("invalid build ID: %s", e.buildID)
    14  }
    15  
    16  type buildIDNotFoundError struct {
    17  	buildID string
    18  }
    19  
    20  func (e buildIDNotFoundError) Error() string {
    21  	return fmt.Sprintf("build ID not found: %s", e.buildID)
    22  }
    23  
    24  type httpStatusError struct {
    25  	statusCode int
    26  	body       string
    27  }
    28  
    29  func (e httpStatusError) Error() string {
    30  	if e.body != "" {
    31  		return fmt.Sprintf("HTTP error %d: %s", e.statusCode, e.body)
    32  	}
    33  	return fmt.Sprintf("HTTP error %d", e.statusCode)
    34  }
    35  
    36  // Helper function to check if an error is of a specific type
    37  func isInvalidBuildIDError(err error) bool {
    38  	var invalidBuildIDError invalidBuildIDError
    39  	ok := errors.As(err, &invalidBuildIDError)
    40  	return ok
    41  }
    42  
    43  func isHTTPStatusError(err error) (int, bool) {
    44  	var httpErr httpStatusError
    45  	ok := errors.As(err, &httpErr)
    46  	if ok {
    47  		return httpErr.statusCode, true
    48  	}
    49  	return 0, false
    50  }