Use native configuration validation and diagnostics

This commit is contained in:
2026-11-20 15:22:57 +00:00
parent 7e45ffca43
commit 39b4bddbc9
47 changed files with 351 additions and 308 deletions

View File

@@ -1,8 +1,6 @@
package config
import (
"bytes"
"errors"
"fmt"
"os"
"path/filepath"
@@ -48,7 +46,7 @@ func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*Pipeline
}
result, err := loadPipelineConfigKitResult(source, overlay, opts.Overrides)
if err != nil {
return nil, describePipelineLoadError(err)
return nil, fmt.Errorf("load pipeline config: %w", err)
}
cfg := &result.Config
cfg.resolution = pipelineMetadataFromConfigKit(result, opts)
@@ -74,43 +72,6 @@ func loadPipelineConfigKitResult(source configkit.Source, overlay string, overri
})
}
func describePipelineLoadError(err error) error {
return describeConfigKitLoadError("pipeline", err)
}
func describeConfigKitLoadError(kind string, err error) error {
var loadError *configkit.LoadError
if !errors.As(err, &loadError) {
return fmt.Errorf("load %s config: %w", kind, err)
}
var diagnostics bytes.Buffer
resolved := loadError.Diagnostics()
sourcePaths := make(map[string]string, len(loadError.Sources()))
for _, source := range loadError.Sources() {
if source.Path != "" {
sourcePaths[source.ID] = source.Path
} else if source.Label != "" {
sourcePaths[source.ID] = source.Label
}
}
for index := range resolved {
if resolved[index].Primary != nil {
if name := sourcePaths[resolved[index].Primary.SourceID]; name != "" {
resolved[index].Primary.SourceID = name
}
}
for relatedIndex := range resolved[index].Related {
if name := sourcePaths[resolved[index].Related[relatedIndex].SourceID]; name != "" {
resolved[index].Related[relatedIndex].SourceID = name
}
}
}
if writeErr := configkit.WriteDiagnostics(&diagnostics, resolved); writeErr != nil {
return fmt.Errorf("load %s config: %w", kind, err)
}
return fmt.Errorf("load %s config: strict decode failed or validation failed: %w: %s", kind, err, strings.TrimSpace(diagnostics.String()))
}
func selectedPipelineOverlayName(opts PipelineLoadOptions) string {
if opts.Overlay == nil || *opts.Overlay == "" || *opts.Overlay == "default" {
return ""