Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7406616794 | |||
| 4939fdb283 |
@@ -45,6 +45,10 @@ boundary and constraints that framework work must preserve.
|
||||
|
||||
## Release Guidance
|
||||
|
||||
The [v0.23.1 release notes](docs/releases/v0.23.1.md) cover corrected constructor
|
||||
error wrapping for downstream classification, with loading diagnostics and
|
||||
underlying causes preserved.
|
||||
|
||||
The [v0.23.0 release notes](docs/releases/v0.23.0.md) cover per-operation
|
||||
timeouts and opt-in prepared-request notifications for ordinary and coordinated
|
||||
execution.
|
||||
|
||||
@@ -215,6 +215,49 @@ func TestPublicConstructionPreservesConfigKitLoadError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicConstructionPreservesMalformedYAMLCause(t *testing.T) {
|
||||
const sourceLabel = "prompts.yml"
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{
|
||||
Source: configkit.Bytes(sourceLabel, []byte("profiles: [\n")),
|
||||
}}})
|
||||
var loadErr *configkit.LoadError
|
||||
if engine != nil || !errors.Is(err, promptkit.ErrInvalidConfig) || !errors.As(err, &loadErr) {
|
||||
t.Fatalf("construction = (%#v, %v), want invalid config preserving LoadError", engine, err)
|
||||
}
|
||||
cause := errors.Unwrap(err)
|
||||
var causeLoadErr *configkit.LoadError
|
||||
if cause == nil || errors.Is(cause, promptkit.ErrInvalidConfig) || !errors.As(cause, &causeLoadErr) || causeLoadErr != loadErr {
|
||||
t.Fatalf("construction cause = %v, want the original loading failure without a category branch", cause)
|
||||
}
|
||||
for _, diagnostic := range loadErr.Diagnostics() {
|
||||
if diagnostic.Code != "yaml.invalid" {
|
||||
continue
|
||||
}
|
||||
if diagnostic.Primary == nil {
|
||||
t.Fatal("YAML diagnostic has no source location")
|
||||
}
|
||||
source, ok := loadErr.Source(diagnostic.Primary.SourceID)
|
||||
if !ok || source.Label != sourceLabel {
|
||||
t.Fatalf("YAML diagnostic source = %+v, found=%v, want %q", source, ok, sourceLabel)
|
||||
}
|
||||
return
|
||||
}
|
||||
t.Fatalf("loading diagnostics = %+v, want yaml.invalid", loadErr.Diagnostics())
|
||||
}
|
||||
|
||||
func TestPublicConstructionPreservesOptionFailureCause(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "missing.json")
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{}, promptkit.WithSchemaFile(path))
|
||||
if engine != nil || !errors.Is(err, promptkit.ErrInvalidConfig) || !errors.Is(err, os.ErrNotExist) {
|
||||
t.Fatalf("construction = (%#v, %v), want invalid config preserving the missing-file cause", engine, err)
|
||||
}
|
||||
cause := errors.Unwrap(err)
|
||||
var pathErr *os.PathError
|
||||
if cause == nil || errors.Is(cause, promptkit.ErrInvalidConfig) || !errors.As(cause, &pathErr) || pathErr.Path != path {
|
||||
t.Fatalf("construction cause = %v, want the original path error without a category branch", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicConstructionRejectsSuppliedInvalidMainInput(t *testing.T) {
|
||||
main := configkit.Input{}
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &main}})
|
||||
|
||||
33
docs/releases/v0.23.1.md
Normal file
33
docs/releases/v0.23.1.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Promptkit v0.23.1
|
||||
|
||||
This patch release fixes construction-error wrapping so downstream consumers
|
||||
can classify failures from their underlying causes without treating the
|
||||
`ErrInvalidConfig` category as an independent failure.
|
||||
|
||||
## Fixed
|
||||
|
||||
`NewEngine` now uses single-cause wrapping for both configuration-loading and
|
||||
option-application failures. `errors.Is` still recognizes `ErrInvalidConfig`,
|
||||
and `errors.As` still exposes ConfigKit loading errors with their diagnostics
|
||||
and source context. Genuine joined causes, including cancellation, remain
|
||||
inspectable. Consumers retain responsibility for mapping those failures to
|
||||
application outcomes or exit statuses.
|
||||
|
||||
See the [constructor GoDoc](../../engine.go) and
|
||||
[error-handling guide](../consumers/pkg-promptkit.md#handle-errors) for the
|
||||
public error contracts and usage.
|
||||
|
||||
## Compatibility And Upgrade
|
||||
|
||||
No configuration or request changes are required when upgrading from v0.23.0.
|
||||
Consumers that inspect constructor error trees directly should account for
|
||||
the category no longer appearing as a separate sibling branch; use
|
||||
`errors.Is` and `errors.As` for category and typed-cause inspection.
|
||||
|
||||
The Go consumer minimum remains 1.27.0, and dependency versions are unchanged.
|
||||
|
||||
```sh
|
||||
go get go.maximumdirect.net/promptkit@v0.23.1
|
||||
```
|
||||
|
||||
[COPYRIGHT](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.23.1/COPYRIGHT) | [LICENSE](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.23.1/LICENSE) | [ATTRIBUTION](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.23.1/docs/oss/attribution.md)
|
||||
16
engine.go
16
engine.go
@@ -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
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ type publicOperationError struct {
|
||||
message string
|
||||
}
|
||||
|
||||
func newPublicOperationError(owner, cause error) *publicOperationError {
|
||||
return &publicOperationError{owner: owner, cause: cause, message: fmt.Sprintf("%v: %v", owner, cause)}
|
||||
}
|
||||
|
||||
func (e *publicOperationError) Error() string { return e.message }
|
||||
func (e *publicOperationError) Unwrap() error { return e.cause }
|
||||
func (e *publicOperationError) Is(target error) bool { return errors.Is(e.owner, target) }
|
||||
@@ -44,7 +48,7 @@ func mapPublicError(err error) error {
|
||||
}
|
||||
// The projection already retains ordinary causes; adding the original
|
||||
// again would duplicate its entire subtree at each enclosing operation.
|
||||
return &publicOperationError{owner: owner, cause: mapped, message: fmt.Sprintf("%v: %v", owner, mapped)}
|
||||
return newPublicOperationError(owner, mapped)
|
||||
}
|
||||
}
|
||||
return mapUnownedPublicError(err)
|
||||
|
||||
@@ -10,6 +10,25 @@ import (
|
||||
"go.maximumdirect.net/promptkit/internal/usecase"
|
||||
)
|
||||
|
||||
func TestConstructionErrorPreservesJoinedCause(t *testing.T) {
|
||||
operational := errors.New("independent operational failure")
|
||||
cause := errors.Join(operational, context.Canceled)
|
||||
engine, err := NewEngine(Config{}, optionFunc(func(*engineOptions) error {
|
||||
return cause
|
||||
}))
|
||||
if engine != nil || err == nil {
|
||||
t.Fatalf("construction = (%#v, %v), want failure", engine, err)
|
||||
}
|
||||
if unwrapped := errors.Unwrap(err); unwrapped != cause {
|
||||
t.Fatalf("construction cause = %v, want the unchanged joined cause", unwrapped)
|
||||
}
|
||||
for _, target := range []error{ErrInvalidConfig, operational, context.Canceled} {
|
||||
if !errors.Is(err, target) {
|
||||
t.Errorf("construction error = %v, want identity %v", err, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapPublicErrorPreservesGenerationCancellation(t *testing.T) {
|
||||
internalErr := fmt.Errorf("%w: %w", usecase.ErrLLMGenerate, context.Canceled)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user