Skip to content

Commit

Permalink
Merge pull request #311 from square/nathan-fenner-uncapitalize-errors
Browse files Browse the repository at this point in the history
lowercase error messages for better composability
  • Loading branch information
drcapulet authored Jun 30, 2016
2 parents 3f6c6ce + 5048b70 commit ec7639d
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 24 deletions.
8 changes: 4 additions & 4 deletions demo/emit/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func reportMetric(client *http.Client, value float64, name string, options ...in

request, err := http.NewRequest("POST", *bluefloodAddress, bytes.NewBuffer([]byte(json)))
if err != nil {
return fmt.Errorf("Error creating Blueflood request: %s\n", err.Error())
return fmt.Errorf("error creating Blueflood request: %s\n", err.Error())
}
response, err := client.Do(request)
if err != nil {
return fmt.Errorf("Error performing Blueflood POST: %s\n", err.Error())
return fmt.Errorf("error performing Blueflood POST: %s\n", err.Error())
}
fmt.Println("Blueflood: ", response.Status)
body, _ := ioutil.ReadAll(response.Body)
Expand All @@ -126,11 +126,11 @@ func reportMetric(client *http.Client, value float64, name string, options ...in

request, err = http.NewRequest("POST", *mqeIngestionAddress, bytes.NewBuffer([]byte(metricName)))
if err != nil {
return fmt.Errorf("Error creating MQE Ingestion request: %s\n", err.Error())
return fmt.Errorf("error creating MQE Ingestion request: %s\n", err.Error())
}
response, err = client.Do(request)
if err != nil {
return fmt.Errorf("Error performing MQE Ingestion POST: %s\n", err.Error())
return fmt.Errorf("error performing MQE Ingestion POST: %s\n", err.Error())
}
fmt.Println("MQE: ", response.Status)
body, _ = ioutil.ReadAll(response.Body)
Expand Down
2 changes: 1 addition & 1 deletion function/builtin/forecast/anomaly_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func standardDeviationsFromExpected(correct []float64, estimate []float64) ([]fl
}
func periodicStandardDeviationsFromExpected(correct []float64, estimate []float64, period int) ([]float64, error) {
if period <= 0 {
return nil, fmt.Errorf("Period must be strictly positive")
return nil, fmt.Errorf("period must be strictly positive")
}
if len(correct) != len(estimate) {
return nil, fmt.Errorf("to estimate anomaly values, the ground truth and estimate slices must be the same length")
Expand Down
6 changes: 3 additions & 3 deletions function/builtin/forecast/rolling_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var FunctionRollingMultiplicativeHoltWinters = function.MakeFunction(
extraTrainingTime = *optionalExtraTrainingTime
}
if extraTrainingTime < 0 {
return api.SeriesList{}, fmt.Errorf("Extra training time must be non-negative, but got %s", extraTrainingTime.String()) // TODO: use structured error
return api.SeriesList{}, fmt.Errorf("extra training time must be non-negative, but got %s", extraTrainingTime.String()) // TODO: use structured error
}

samples := int(period / context.Timerange().Resolution())
Expand Down Expand Up @@ -76,7 +76,7 @@ var FunctionRollingSeasonal = function.MakeFunction(
extraTrainingTime = *optionalExtraTrainingTime
}
if extraTrainingTime < 0 {
return api.SeriesList{}, fmt.Errorf("Extra training time must be non-negative, but got %s", extraTrainingTime.String()) // TODO: use structured error
return api.SeriesList{}, fmt.Errorf("extra training time must be non-negative, but got %s", extraTrainingTime.String()) // TODO: use structured error
}

samples := int(period / context.Timerange().Resolution())
Expand Down Expand Up @@ -117,7 +117,7 @@ var FunctionLinear = function.MakeFunction(
extraTrainingTime = *optionalTrainingTime
}
if extraTrainingTime < 0 {
return api.SeriesList{}, fmt.Errorf("Extra training time must be non-negative, but got %s", extraTrainingTime.String()) // TODO: use structured error
return api.SeriesList{}, fmt.Errorf("extra training time must be non-negative, but got %s", extraTrainingTime.String()) // TODO: use structured error
}

newContext := context.WithTimerange(context.Timerange().ExtendBefore(extraTrainingTime))
Expand Down
5 changes: 0 additions & 5 deletions function/builtin/forecast/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ package forecast

import "math"

// Returns the unique integer r such that x == r (mod m) and 0 <= r < m
func mod(x int, m int) int {
return ((x % m) + m) % m
}

// LinearRegression estimates ys as (a + b*t) and returns (a, b).
// It performs linear regression using the explicit form for minimization of least-squares error.
// When ys[i] is NaN, it is treated as a missing point. (This makes things only slightly more complicated).
Expand Down
2 changes: 1 addition & 1 deletion function/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

var dummyCompute = func(function.EvaluationContext, []function.Expression, function.Groups) (function.Value, error) {
return nil, errors.New("Not implemented")
return nil, errors.New("not implemented")
}

func Test_Registry_Default(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion main/ruletester/ruletester.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ReadMetricsFile(file string) ([]string, error) {
r, err := zlib.NewReader(bytes.NewBuffer(data))
defer r.Close()
if err != nil {
return nil, fmt.Errorf("Problem with zlib compressed data: %s", err.Error())
return nil, fmt.Errorf("problem with zlib compressed data: %s", err.Error())
}

// Store the result of the decode in this map:
Expand Down
2 changes: 1 addition & 1 deletion metric_metadata/cached/cached.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (c *metricMetadataAPI) CheckHealthy() error {
// item in the cache.
func (c *metricMetadataAPI) fetchAndUpdateCachedTagSet(item *TagSetList, metricKey api.MetricKey, context metadata.Context) ([]api.TagSet, error) {
if item == nil {
return nil, errors.New("Missing cache list entry")
return nil, errors.New("missing cache list entry")
}

item.wg.Add(1)
Expand Down
2 changes: 1 addition & 1 deletion query/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (cmd *SelectCommand) Execute(context ExecutionContext) (Result, error) {
}
continue
}
return Result{}, fmt.Errorf("Query %s does not result in a timeseries or scalar.", cmd.Expressions[i].ExpressionString(function.StringQuery))
return Result{}, fmt.Errorf("query %s does not result in a timeseries or scalar.", cmd.Expressions[i].ExpressionString(function.StringQuery))
}

return Result{
Expand Down
3 changes: 2 additions & 1 deletion query/expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ type AnnotationExpression struct {
Annotation string
}

// AnnotationExpression implements Evaluate rather than ActualEvaluate so that it doesn't cause memoization.
// Evaluate evalutes the underlying expression without memoization, since its
// child expression should handle memoization itself.
func (expr *AnnotationExpression) Evaluate(context function.EvaluationContext) (function.Value, error) {
return expr.Expression.Evaluate(context)
}
Expand Down
4 changes: 2 additions & 2 deletions testing_support/mocks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ func (fa *FakeGraphiteConverter) ToGraphiteName(metric api.TaggedMetric) (util.G
return k, nil
}
}
return "", fmt.Errorf("No mapping for tagged metric %+v to tagged metric", metric)
return "", fmt.Errorf("no mapping for tagged metric %+v to tagged metric", metric)
}

func (fa *FakeGraphiteConverter) ToTaggedName(metric util.GraphiteMetric) (api.TaggedMetric, error) {
tm, exists := fa.MetricMap[metric]
if !exists {
return api.TaggedMetric{}, fmt.Errorf("No mapping for graphite metric %+s to graphite metric", string(metric))
return api.TaggedMetric{}, fmt.Errorf("no mapping for graphite metric %+s to graphite metric", string(metric))
}

return tm, nil
Expand Down
2 changes: 1 addition & 1 deletion testing_support/mocks/combo_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var _ metadata.MetricAPI = FakeComboAPI{}

func (fapi FakeComboAPI) ChooseResolution(requested api.Timerange, smallestResolution time.Duration) (time.Duration, error) {
if requested.Resolution() != fapi.timerange.Resolution() {
return 0, fmt.Errorf("FakeComboAPI has internal resolution %+v but user requested %+v", fapi.timerange.Resolution(), requested.Resolution())
return 0, fmt.Errorf("the FakeComboAPI has internal resolution %+v but user requested %+v", fapi.timerange.Resolution(), requested.Resolution())
}
return requested.Resolution(), nil
}
Expand Down
2 changes: 1 addition & 1 deletion testing_support/mocks/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *FakeHTTPClient) SetResponse(url string, r Response) {
func (c *FakeHTTPClient) Get(url string) (*http.Response, error) {
r, exists := c.responses[url]
if !exists {
return nil, fmt.Errorf("Get() received unexpected url %s, mappings: %+v", url, c.responses)
return nil, fmt.Errorf("the FakeHTTPClient's Get() method received unexpected url %s, mappings: %+v", url, c.responses)
}

if r.Delay > 0 {
Expand Down
2 changes: 1 addition & 1 deletion timeseries/blueflood/blueflood.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (b *Blueflood) CheckHealthy() error {
if err != nil {
return err
}
return fmt.Errorf("Blueflood returned an unhealthy status of %d: %s", resp.StatusCode, string(body))
return fmt.Errorf("the Blueflood instance returned an unhealthy status of %d: %s", resp.StatusCode, string(body))
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion timeseries/blueflood/plan_intervals.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func planFetchIntervalsWithOnlyFiner(resolutions []Resolution, now time.Time, re
for i := range resolutions {
if resolutions[i].Resolution > requestRange.Resolution() {
if i == 0 {
return nil, fmt.Errorf("No resolutions are available at least as fine as the chosen %+v", requestRange.Resolution())
return nil, fmt.Errorf("no resolutions are available at least as fine as the chosen %+v", requestRange.Resolution())
}
return planFetchIntervals(resolutions[:i], now, requestRange.Interval())
}
Expand Down

0 comments on commit ec7639d

Please sign in to comment.