Skip to content

Commit

Permalink
Remove custom error types
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenz Kästle committed Jun 20, 2024
1 parent 59dacbe commit 643ee88
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions perfdata/type.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package perfdata

import (
"errors"
"fmt"
"math"
"strings"
Expand All @@ -11,20 +12,6 @@ import (
// Replace not allowed characters inside a label
var replacer = strings.NewReplacer("=", "_", "`", "_", "'", "_", "\"", "_")

type InfValueError struct {
}

func (i InfValueError) Error() string {
return "Performance data value is infinite"
}

type NanValueError struct {
}

func (i NanValueError) Error() string {
return "Performance data value is NaN (not a number)"
}

// formatNumeric returns a string representation of various possible numerics
//
// This supports most internal types of Go and all fmt.Stringer interfaces.
Expand All @@ -36,21 +23,21 @@ func formatNumeric(value interface{}) (string, error) {
switch v := value.(type) {
case float64:
if math.IsInf(v, 0) {
return "", InfValueError{}
return "", errors.New("Perfdata value is inifinite")
}

if math.IsNaN(v) {
return "", NanValueError{}
return "", errors.New("Perfdata value is inifinite")
}

return check.FormatFloat(v), nil
case float32:
if math.IsInf(float64(v), 0) {
return "", InfValueError{}
return "", errors.New("Perfdata value is inifinite")
}

if math.IsNaN(float64(v)) {
return "", NanValueError{}
return "", errors.New("Perfdata value is inifinite")
}

return check.FormatFloat(float64(v)), nil
Expand Down

0 comments on commit 643ee88

Please sign in to comment.