...
1
16
17 package main
18
19 import (
20 "fmt"
21 "go/ast"
22 "go/token"
23 )
24
25 const (
26 errNotDirectCall = "Opts for STABLE metric was not directly passed to new metric function"
27 errPositionalArguments = "Positional arguments are not supported"
28 errStabilityLevel = "StabilityLevel should be passed STABLE, BETA, ALPHA or removed"
29 errInvalidNewMetricCall = "Invalid new metric call, please ensure code compiles"
30 errNonStringAttribute = "Non string attribute is not supported"
31 errBadVariableAttribute = "Metric attribute was not correctly set. Please use only global consts in same file"
32 errBadImportedVariableAttribute = "Metric attribute was not correctly set. Please use only global consts in correctly imported same file"
33 errFieldNotSupported = "Field %s is not supported"
34 errBuckets = "Buckets should be set to list of floats, result from function call of prometheus.LinearBuckets or prometheus.ExponentialBuckets"
35 errObjectives = "Objectives should be set to map of floats to floats"
36 errDecodeUint32 = "Should decode to uint32"
37 errDecodeInt64 = "Should decode to int64"
38
39 errLabels = "Labels were not set to list of strings"
40 errImport = `Importing using "." is not supported`
41 errExprNotIdent = "expr selector does not refer to type ast.Ident, is type %s"
42
43 errorDecodingString = "can't decode string"
44 errorDecodingLabels = "can't decode labels"
45 errorDecodingConstLabels = "can't decode const labels"
46 errorDecodingStabilityLevel = "can't decode stability level"
47 errorFindingVariableForBuckets = "couldn't find variable for bucket"
48 errorFindingVariableForLabels = "couldn't find variable for labels"
49 )
50
51 type decodeError struct {
52 msg string
53 pos token.Pos
54 }
55
56 func newDecodeErrorf(node ast.Node, format string, a ...interface{}) *decodeError {
57 return &decodeError{
58 msg: fmt.Sprintf(format, a...),
59 pos: node.Pos(),
60 }
61 }
62
63 var _ error = (*decodeError)(nil)
64
65 func (e decodeError) Error() string {
66 return e.msg
67 }
68
69 func (e decodeError) errorWithFileInformation(fileset *token.FileSet) error {
70 position := fileset.Position(e.pos)
71 return fmt.Errorf("%s:%d:%d: %s", position.Filename, position.Line, position.Column, e.msg)
72 }
73
View as plain text