Honor cancellation at standard inspection boundaries
This commit is contained in:
26
promptkit.go
26
promptkit.go
@@ -70,6 +70,11 @@ func loadPromptKitInspection[C any](ctx context.Context, selection Selection, ap
|
||||
if engine == nil {
|
||||
return nil, promptkit.ConfigurationInspection{}, nil, fmt.Errorf("PromptKit configuration loader returned a nil engine")
|
||||
}
|
||||
if ctx != nil {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, promptkit.ConfigurationInspection{}, nil, err
|
||||
}
|
||||
}
|
||||
inspection, err := engine.InspectConfiguration()
|
||||
if err != nil {
|
||||
return nil, promptkit.ConfigurationInspection{}, nil, err
|
||||
@@ -264,11 +269,20 @@ func newPromptKitProfileCommand[C any](suite PromptKitSuite[C]) (Command, error)
|
||||
}
|
||||
|
||||
func runPromptKitPrompt[C any](invocation Invocation, suite PromptKitSuite[C], input promptKitInput[C]) Outcome {
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return Failure(err)
|
||||
}
|
||||
contextValue := promptKitContext(suite, input)
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return Failure(err)
|
||||
}
|
||||
acquired, err := suite.InspectPrompt(invocation.Context, input.Selection, contextValue, input.ID, input.Version)
|
||||
if err != nil {
|
||||
return promptKitFailure(err, acquired.Diagnostics)
|
||||
}
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return promptKitFailure(err, acquired.Diagnostics)
|
||||
}
|
||||
if acquired.Value == nil {
|
||||
return promptKitFailure(fmt.Errorf("PromptKit prompt inspection returned no result"), acquired.Diagnostics)
|
||||
}
|
||||
@@ -277,11 +291,20 @@ func runPromptKitPrompt[C any](invocation Invocation, suite PromptKitSuite[C], i
|
||||
}
|
||||
|
||||
func runPromptKitProfile[C any](invocation Invocation, suite PromptKitSuite[C], input promptKitInput[C]) Outcome {
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return Failure(err)
|
||||
}
|
||||
contextValue := promptKitContext(suite, input)
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return Failure(err)
|
||||
}
|
||||
acquired, err := suite.InspectProfile(invocation.Context, input.Selection, contextValue, input.ID)
|
||||
if err != nil {
|
||||
return promptKitFailure(err, acquired.Diagnostics)
|
||||
}
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return promptKitFailure(err, acquired.Diagnostics)
|
||||
}
|
||||
if acquired.Value == nil {
|
||||
return promptKitFailure(fmt.Errorf("PromptKit profile inspection returned no result"), acquired.Diagnostics)
|
||||
}
|
||||
@@ -308,6 +331,9 @@ func writePromptKitReport(invocation Invocation, format string, report any, text
|
||||
} else if _, err := io.WriteString(&output, textReport); err != nil {
|
||||
return promptKitFailure(err, diagnostics)
|
||||
}
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return promptKitFailure(err, diagnostics)
|
||||
}
|
||||
if err := writeReport(invocation.Streams.Out, []byte(output.String())); err != nil {
|
||||
outcome := incompleteReport(err)
|
||||
outcome.Diagnostics = diagnostics
|
||||
|
||||
Reference in New Issue
Block a user