package configkit import ( "io" "go.maximumdirect.net/configkit/internal/engine" ) // LoadError reports safe structured diagnostics for a failed configuration load. // It intentionally does not expose or unwrap parser and application errors. type LoadError struct{ value *engine.LoadError } // Error implements error without rendering diagnostic messages or input values. func (e *LoadError) Error() string { if e == nil || e.value == nil { return "configkit: configuration load failed" } return e.value.Error() } // Diagnostics returns a deep copy of the error's canonical diagnostics. func (e *LoadError) Diagnostics() []Diagnostic { if e == nil || e.value == nil { return nil } values := e.value.Diagnostics() if values == nil { return nil } result := make([]Diagnostic, len(values)) for i := range values { result[i] = fromEngineDiagnostic(values[i]) } return result } // Sources returns a deep copy of sources discovered before loading failed. func (e *LoadError) Sources() []SourceInfo { if e == nil || e.value == nil { return nil } values := e.value.Sources() if values == nil { return nil } result := make([]SourceInfo, len(values)) for i := range values { result[i] = fromEngineSourceInfo(values[i]) } return result } // Source returns a detached record from the sanitized source evidence retained // before loading failed, including placement evidence available at that point. // IDs are local to the failed load. It does not acquire sources or access the // filesystem. Empty or unknown IDs return false. func (e *LoadError) Source(id string) (SourceInfo, bool) { if e == nil || e.value == nil { return SourceInfo{}, false } value, ok := e.value.Source(id) if !ok { return SourceInfo{}, false } return fromEngineSourceInfo(value), true } // WriteDiagnostics writes diagnostics in canonical order. It escapes terminal // control characters and propagates writer errors, including short writes. func WriteDiagnostics(output io.Writer, diagnostics []Diagnostic) error { return engine.WriteDiagnostics(output, toEngineDiagnostics(diagnostics)) }