Skip to content

Commit 27e9a61

Browse files
committed
Update error usages
1 parent 68c8c22 commit 27e9a61

File tree

37 files changed

+175
-144
lines changed

37 files changed

+175
-144
lines changed

expr/expr.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package expr
22

33
import (
44
"context"
5+
"github.com/go-graphite/carbonapi/pkg/errors"
56

67
utilctx "github.com/go-graphite/carbonapi/util/ctx"
78

@@ -149,8 +150,7 @@ func EvalExpr(ctx context.Context, e parser.Expr, from, until int64, values map[
149150

150151
// all functions have arguments -- check we do too
151152
if e.ArgsLen() == 0 {
152-
err := merry.WithMessagef(parser.ErrMissingArgument, "target=%s: %s", e.Target(), parser.ErrMissingArgument)
153-
return nil, merry.WithHTTPCode(err, 400)
153+
return nil, errors.ErrMissingArgument{Target: e.Target()}
154154
}
155155

156156
metadata.FunctionMD.RLock()
@@ -177,7 +177,7 @@ func EvalExpr(ctx context.Context, e parser.Expr, from, until int64, values map[
177177
return v, err
178178
}
179179

180-
return nil, merry.WithHTTPCode(helper.ErrUnknownFunction(e.Target()), 400)
180+
return nil, errors.ErrUnknownFunction(e.Target())
181181
}
182182

183183
// RewriteExpr expands targets that use applyByNode into a new list of targets.

expr/functions/aggregate/function.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package aggregate
22

33
import (
44
"context"
5-
"fmt"
5+
"github.com/go-graphite/carbonapi/pkg/errors"
66
"strings"
77

88
"github.com/go-graphite/carbonapi/expr/consolidations"
@@ -77,7 +77,7 @@ func (f *aggregate) Do(ctx context.Context, e parser.Expr, from, until int64, va
7777

7878
aggFunc, ok := consolidations.ConsolidationToFunc[callback]
7979
if !ok {
80-
return nil, fmt.Errorf("unsupported consolidation function %s", callback)
80+
return nil, errors.ErrUnsupportedConsolidationFunction{Target: e.Target(), Func: callback}
8181
}
8282
target := callback + "Series"
8383

expr/functions/aggregateLine/function.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package aggregateLine
22

33
import (
44
"context"
5-
"fmt"
5+
"github.com/go-graphite/carbonapi/pkg/errors"
66
"math"
77
"strconv"
88

@@ -59,7 +59,7 @@ func (f *aggregateLine) Do(ctx context.Context, e parser.Expr, from, until int64
5959

6060
aggFunc, ok := consolidations.ConsolidationToFunc[callback]
6161
if !ok {
62-
return nil, fmt.Errorf("unsupported consolidation function %s", callback)
62+
return nil, errors.ErrUnsupportedConsolidationFunction{Target: e.Target(), Func: callback}
6363
}
6464

6565
results := make([]*types.MetricData, len(args))

expr/functions/aggregateSeriesLists/function.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package aggregateSeriesLists
22

33
import (
44
"context"
5-
"fmt"
5+
"github.com/go-graphite/carbonapi/pkg/errors"
66

77
"github.com/go-graphite/carbonapi/expr/consolidations"
88
"github.com/go-graphite/carbonapi/expr/helper"
@@ -39,7 +39,7 @@ func (f *aggregateSeriesLists) Do(ctx context.Context, e parser.Expr, from, unti
3939
}
4040

4141
if len(seriesList1) != len(seriesList2) {
42-
return nil, fmt.Errorf("seriesListFirstPos and seriesListSecondPos must have equal length")
42+
return nil, errors.ErrBadData{Target: e.Target(), Msg: "seriesListFirstPos and seriesListSecondPos must have equal length"}
4343
} else if len(seriesList1) == 0 {
4444
return make([]*types.MetricData, 0, 0), nil
4545
}
@@ -50,7 +50,7 @@ func (f *aggregateSeriesLists) Do(ctx context.Context, e parser.Expr, from, unti
5050
}
5151
aggFunc, ok := consolidations.ConsolidationToFunc[aggFuncStr]
5252
if !ok {
53-
return nil, fmt.Errorf("unsupported consolidation function %s", aggFuncStr)
53+
return nil, errors.ErrUnsupportedConsolidationFunction{Target: e.Target(), Func: aggFuncStr}
5454
}
5555

5656
xFilesFactor, err := e.GetFloatArgDefault(3, float64(seriesList1[0].XFilesFactor))

expr/functions/aggregateWithWildcards/function.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package aggregateWithWildcards
33
import (
44
"context"
55
"fmt"
6+
"github.com/go-graphite/carbonapi/pkg/errors"
67
"strings"
78

89
"github.com/go-graphite/carbonapi/expr/consolidations"
@@ -55,7 +56,7 @@ func (f *aggregateWithWildcards) Do(ctx context.Context, e parser.Expr, from, un
5556

5657
aggFunc, ok := consolidations.ConsolidationToFunc[callback]
5758
if !ok {
58-
return nil, fmt.Errorf("unsupported consolidation function %s", callback)
59+
return nil, errors.ErrUnsupportedConsolidationFunction{Target: e.Target(), Func: callback}
5960
}
6061
target := fmt.Sprintf("%sSeries", callback)
6162
e.SetTarget(target)

expr/functions/asPercent/function.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package asPercent
22

33
import (
44
"context"
5-
"errors"
65
"math"
76
"sort"
87

98
"github.com/go-graphite/carbonapi/expr/helper"
109
"github.com/go-graphite/carbonapi/expr/interfaces"
1110
"github.com/go-graphite/carbonapi/expr/types"
11+
"github.com/go-graphite/carbonapi/pkg/errors"
1212
"github.com/go-graphite/carbonapi/pkg/parser"
1313
)
1414

@@ -433,7 +433,7 @@ func (f *asPercent) Do(ctx context.Context, e parser.Expr, from, until int64, va
433433
}
434434
}
435435

436-
return nil, errors.New("total must be either a constant or a series")
436+
return nil, errors.ErrInvalidArgument{Target: e.Target(), Msg: "total must be either a constant or a series"}
437437
}
438438

439439
// Description is auto-generated description, based on output of https://github.com/graphite-project/graphite-web

expr/functions/cactiStyle/function.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cactiStyle
33
import (
44
"context"
55
"fmt"
6+
"github.com/go-graphite/carbonapi/pkg/errors"
67
"math"
78
"strings"
89

@@ -92,7 +93,7 @@ func (f *cactiStyle) Do(ctx context.Context, e parser.Expr, from, until int64, v
9293
current = fmt.Sprintf("%.0f", currentVal)
9394

9495
} else {
95-
return nil, fmt.Errorf("%s is not supported for system", system)
96+
return nil, errors.ErrBadData{Target: e.Target(), Msg: system + "is not supported for system"}
9697
}
9798

9899
// Append the unit if specified

expr/functions/cairo/png/cairo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ func EvalExprGraph(ctx context.Context, e parser.Expr, from, until int64, values
879879

880880
}
881881

882-
return nil, helper.ErrUnknownFunction(e.Target())
882+
return nil, errors.ErrUnknownFunction(e.Target())
883883
}
884884

885885
func MarshalSVG(params PictureParams, results []*types.MetricData) []byte {

expr/functions/divideSeries/function.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package divideSeries
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
6+
"github.com/go-graphite/carbonapi/pkg/errors"
77
"math"
88

99
"github.com/go-graphite/carbonapi/expr/helper"
@@ -33,7 +33,7 @@ func New(configFile string) []interfaces.FunctionMetadata {
3333
// divideSeries(dividendSeriesList, divisorSeriesList)
3434
func (f *divideSeries) Do(ctx context.Context, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error) {
3535
if e.ArgsLen() < 1 {
36-
return nil, parser.ErrMissingTimeseries
36+
return nil, errors.ErrMissingTimeseries{Target: e.Target()}
3737
}
3838

3939
firstArg, err := helper.GetSeriesArg(ctx, e.Arg(0), from, until, values)
@@ -69,15 +69,15 @@ func (f *divideSeries) Do(ctx context.Context, e parser.Expr, from, until int64,
6969
}
7070

7171
if len(denominators) > 1 {
72-
return nil, types.ErrWildcardNotAllowed
72+
return nil, errors.ErrWildcardNotAllowed{Target: e.Target(), Arg: e.Arg(1).ToString()}
7373
}
7474

7575
denominator = denominators[0]
7676
} else if len(firstArg) == 2 && e.ArgsLen() == 1 {
7777
numerators = append(numerators, firstArg[0])
7878
denominator = firstArg[1]
7979
} else {
80-
return nil, errors.New("must be called with 2 series or a wildcard that matches exactly 2 series")
80+
return nil, errors.ErrBadData{Target: e.Target(), Msg: "must be called with 2 series or a wildcard that matches exactly 2 series"}
8181
}
8282

8383
for _, numerator := range numerators {

expr/functions/exponentialMovingAverage/function.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package exponentialMovingAverage
33
import (
44
"context"
55
"fmt"
6+
"github.com/go-graphite/carbonapi/pkg/errors"
67
"math"
78
"strconv"
89

@@ -38,7 +39,7 @@ func (f *exponentialMovingAverage) Do(ctx context.Context, e parser.Expr, from,
3839
var argstr string
3940

4041
if len(e.Args()) < 2 {
41-
return nil, parser.ErrMissingArgument
42+
return nil, errors.ErrMissingArgument{Target: e.Target()}
4243
}
4344

4445
switch e.Args()[1].Type() {
@@ -56,7 +57,7 @@ func (f *exponentialMovingAverage) Do(ctx context.Context, e parser.Expr, from,
5657
argstr = fmt.Sprintf("%q", e.Args()[1].StringValue())
5758
n = int(n32)
5859
default:
59-
err = parser.ErrBadType
60+
err = errors.ErrBadType{Target: e.Target(), Arg: e.Arg(1).ToString(), Exp: []parser.ExprType{parser.EtConst, parser.EtString}, Got: e.Args()[1].Type()}
6061
}
6162
if err != nil {
6263
return nil, err
@@ -84,7 +85,7 @@ func (f *exponentialMovingAverage) Do(ctx context.Context, e parser.Expr, from,
8485
var vals []float64
8586

8687
if windowSize < 1 && windowSize > len(a.Values) {
87-
return nil, fmt.Errorf("invalid window size %d", windowSize)
88+
return nil, errors.ErrInvalidArgument{Target: e.Target(), Msg: "invalid window size " + string(windowSize)}
8889
}
8990

9091
ema := consolidations.AggMean(a.Values[:windowSize])

0 commit comments

Comments
 (0)