Preserve construction error causes without extra branches

This commit is contained in:
2026-11-16 19:44:09 +00:00
parent fcbff80ab2
commit 4939fdb283
4 changed files with 75 additions and 9 deletions

View File

@@ -241,12 +241,12 @@ func WithSchemaFile(path string) Option {
// content. A missing prompt collection is allowed. Schema documents and
// request artifacts remain runtime resources.
//
// NewEngine returns an error matching ErrInvalidConfig for invalid
// configuration or options, preserving a ConfigKit LoadError when loading
// fails. Each constructed
// Engine has independent backend-capacity pools. Construction does not perform
// model requests or require credentials. A negative Config.TransientRetries
// is invalid.
// NewEngine returns an error matching ErrInvalidConfig through errors.Is for
// invalid configuration or options. The error unwraps to the original
// construction cause, preserving a ConfigKit LoadError when loading fails.
// Each constructed Engine has independent backend-capacity pools. Construction
// does not perform model requests or require credentials. A negative
// Config.TransientRetries is invalid.
func NewEngine(cfg Config, opts ...Option) (*Engine, error) {
var options engineOptions
for _, opt := range opts {
@@ -254,7 +254,7 @@ func NewEngine(cfg Config, opts ...Option) (*Engine, error) {
continue
}
if err := opt.apply(&options); err != nil {
return nil, fmt.Errorf("%w: %w", ErrInvalidConfig, err)
return nil, newPublicOperationError(ErrInvalidConfig, err)
}
}
@@ -263,7 +263,7 @@ func NewEngine(cfg Config, opts ...Option) (*Engine, error) {
options.internal,
)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrInvalidConfig, err)
return nil, newPublicOperationError(ErrInvalidConfig, err)
}
return &Engine{internal: assembled}, nil
}