Improved error reporting.

This commit is contained in:
Christian Schneider
2023-12-13 14:03:22 +01:00
parent 9f92116fe3
commit cd459836a6
2 changed files with 3 additions and 3 deletions

View File

@@ -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)
}
}

View File

@@ -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{}
@@ -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)