add more information to existing errors logs and panics

- '$ROOT/$FILE' for better localization in the code
- add text where none was given
- fix unnecessary sprintf nesting in influxv2 and prometheus metricrepo logging
This commit is contained in:
Christoph Kluge
2023-01-19 16:59:14 +01:00
parent 5abd3641b2
commit 24a4244f19
31 changed files with 254 additions and 253 deletions

View File

@@ -133,12 +133,12 @@ const (
func (e *JobState) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
return fmt.Errorf("SCHEMA/JOB > enums must be strings")
}
*e = JobState(str)
if !e.Valid() {
return errors.New("invalid job state")
return errors.New("SCHEMA/JOB > invalid job state")
}
return nil

View File

@@ -92,12 +92,12 @@ func (e *MetricScope) Max(other MetricScope) MetricScope {
func (e *MetricScope) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
return fmt.Errorf("SCHEMA/METRICS > enums must be strings")
}
*e = MetricScope(str)
if !e.Valid() {
return fmt.Errorf("%s is not a valid MetricScope", str)
return fmt.Errorf("SCHEMA/METRICS > %s is not a valid MetricScope", str)
}
return nil
}
@@ -303,7 +303,7 @@ func (jm *JobMetric) AddPercentiles(ps []int) bool {
for _, p := range ps {
if p < 1 || p > 99 {
panic("invalid percentile")
panic("SCHEMA/METRICS > invalid percentile")
}
if _, ok := jm.StatisticsSeries.Percentiles[p]; ok {

View File

@@ -45,7 +45,7 @@ func Validate(k Kind, r io.Reader) (err error) {
case Config:
s, err = jsonschema.Compile("embedfs://config.schema.json")
default:
return fmt.Errorf("unkown schema kind ")
return fmt.Errorf("SCHEMA/VALIDATE > unkown schema kind: %v", k)
}
if err != nil {
@@ -54,12 +54,12 @@ func Validate(k Kind, r io.Reader) (err error) {
var v interface{}
if err := json.NewDecoder(r).Decode(&v); err != nil {
log.Errorf("schema.Validate() - Failed to decode %v", err)
log.Errorf("SCHEMA/VALIDATE > Failed to decode %v", err)
return err
}
if err = s.Validate(v); err != nil {
return fmt.Errorf("%#v", err)
return fmt.Errorf("SCHEMA/VALIDATE > %#v", err)
}
return nil