Skip to content

Commit

Permalink
Merge pull request grafana#844 from loadimpact/betterInvalidMetricNam…
Browse files Browse the repository at this point in the history
…eReporting

Report the name of the metric that is invalid
  • Loading branch information
mstoykov authored Nov 15, 2018
2 parents a726a47 + 0e663c9 commit 0bb373b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions js/modules/k6/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package metrics
import (
"context"
"errors"
"fmt"
"regexp"
"time"

Expand All @@ -31,10 +32,6 @@ import (
"github.com/loadimpact/k6/stats"
)

// ErrInvalidMetricName is the error returned when the name of the metric is not containeing only
// letters, numbers, hyphens, dots, underscores, dots and both normal and square brackets
var ErrInvalidMetricName = errors.New("Invalid metric name")

var nameRegexString = "^[\\p{L}\\p{N}\\._ -]{1,128}$"

var compileNameRegex = regexp.MustCompile(nameRegexString)
Expand All @@ -57,7 +54,7 @@ func newMetric(ctxPtr *context.Context, name string, t stats.MetricType, isTime

//TODO: move verification outside the JS
if !checkName(name) {
return nil, ErrInvalidMetricName
return nil, common.NewInitContextError(fmt.Sprintf("Invalid metric name: '%s'", name))
}

valueType := stats.Default
Expand Down

0 comments on commit 0bb373b

Please sign in to comment.