Skip to content

Commit

Permalink
Improved error reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Schneider committed Mar 25, 2024
1 parent 9f92116 commit cd45983
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func LoadConfig(configFile string) (Config, error) {
}
if forcesMonotonicy {
if err := os.MkdirAll(cfg.Cache.StateDir, 0755); err != nil {
return Config{}, err
return Config{}, fmt.Errorf("failed to create directory %q: %w", cfg.Cache.StateDir, err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (p *Parser) evalExpression(metricID, code string, value float64) (float64,
ms.env = defaultExprEnv()
ms.program, err = expr.Compile(code, expr.Env(ms.env), expr.AsFloat64())
if err != nil {
return value, fmt.Errorf("failed to compile expression %q: %v", code, err)
return value, fmt.Errorf("failed to compile expression %q: %w", code, err)
}
// Trigger flushing the new state to disk.
ms.lastWritten = time.Time{}
Expand All @@ -346,7 +346,7 @@ func (p *Parser) evalExpression(metricID, code string, value float64) (float64,

result, err := expr.Run(ms.program, ms.env)
if err != nil {
return value, fmt.Errorf("failed to evaluate expression %q: %v", code, err)
return value, fmt.Errorf("failed to evaluate expression %q: %w", code, err)
}
// Type was statically checked above.
ret := result.(float64)
Expand Down

0 comments on commit cd45983

Please sign in to comment.