Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[component] Print path to error in ValidateConfig #12108

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
17 changes: 7 additions & 10 deletions component/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,15 @@
// ValidateConfig validates a config, by doing this:
// - Call Validate on the config itself if the config implements ConfigValidator.
func ValidateConfig(cfg Config) error {
var err error
errs := validate(reflect.ValueOf(cfg))

for _, suberr := range errs {
err = errors.Join(err, suberr.toError())
}

return err
return errors.Join(validate(reflect.ValueOf(cfg)))

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / Integration test

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (cmd-1)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (cmd-1)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (exporter-0)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (exporter-0)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / test-coverage

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / test-coverage

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / test-coverage

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / test-coverage

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / test-coverage

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / test-coverage

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / test-coverage

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (receiver-3)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (receiver-3)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (receiver-2)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (receiver-2)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (connector)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (connector)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (internal)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (internal)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (receiver-0)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (receiver-0)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (extension)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (extension)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (processor)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (processor)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (pkg)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (pkg)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (receiver-1)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (receiver-1)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / unittest-matrix (ubuntu-latest, ~1.22)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / unittest-matrix (ubuntu-latest, ~1.22)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / unittest-matrix (ubuntu-latest, ~1.22)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2025)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2025)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2025)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2025)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2025)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2025)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2025)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (other)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (other)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (exporter-1)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / contrib-tests-matrix (exporter-1)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2022)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2022)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2022)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2022)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2022)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2022)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)

Check failure on line 36 in component/config.go

View workflow job for this annotation

GitHub Actions / windows-unittest (windows-2022)

cannot use validate(reflect.ValueOf(cfg)) (value of type []pathError) as error value in argument to errors.Join: []pathError does not implement error (missing method Error)
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
}

type pathError struct {
err error
path []string
}

func (pe pathError) toError() error {
func (pe pathError) Error() string {
if len(pe.path) > 0 {
var path string
sb := strings.Builder{}
Expand All @@ -60,9 +53,13 @@
}
path = sb.String()

return fmt.Errorf("%s: %w", path, pe.err)
return fmt.Sprintf("%s: %s", path, pe.err)
}

return pe.err.Error()
}

func (pe pathError) Unwrap() error {
return pe.err
}

Expand Down
Loading