Honor cancellation at standard inspection boundaries
This commit is contained in:
19
show.go
19
show.go
@@ -31,6 +31,9 @@ type effectiveDocument struct {
|
||||
}
|
||||
|
||||
func runConfigShow[C any](invocation Invocation, suite ConfigSuite[C], input configInput[C]) Outcome {
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return Failure(err)
|
||||
}
|
||||
scopeNames, err := selectConfigScopes(suite, input, ConfigShow)
|
||||
if err != nil {
|
||||
return Failure(err)
|
||||
@@ -43,17 +46,27 @@ func runConfigShow[C any](invocation Invocation, suite ConfigSuite[C], input con
|
||||
if !ok || scope.Acquire == nil {
|
||||
return showFailure(fmt.Errorf("configuration scope %q has no acquisition callback", name), diagnostics, false)
|
||||
}
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return showFailure(err, diagnostics, false)
|
||||
}
|
||||
acquired, acquireErr := scope.Acquire(invocation.Context, ConfigRequest{Operation: ConfigShow, Selection: input.Selection}, contexts[name])
|
||||
diagnostics = append(diagnostics, acquired.Diagnostics...)
|
||||
if acquireErr != nil {
|
||||
return showFailure(acquireErr, diagnostics, false)
|
||||
}
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return showFailure(err, diagnostics, false)
|
||||
}
|
||||
|
||||
if acquired.Value.Effective == nil {
|
||||
return showFailure(fmt.Errorf("configuration scope %q did not provide an effective configuration writer", name), diagnostics, false)
|
||||
}
|
||||
documents = append(documents, effectiveDocument{name: name, view: acquired.Value})
|
||||
}
|
||||
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return showFailure(err, diagnostics, false)
|
||||
}
|
||||
if len(documents) == 1 && input.Scope != "all" {
|
||||
checked := &checkedWriter{writer: invocation.Streams.Out}
|
||||
renderErr := documents[0].view.Effective.WriteEffective(checked)
|
||||
@@ -76,10 +89,16 @@ func runConfigShow[C any](invocation Invocation, suite ConfigSuite[C], input con
|
||||
|
||||
written := false
|
||||
for index, document := range documents {
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return showFailure(err, diagnostics, written)
|
||||
}
|
||||
var native bytes.Buffer
|
||||
if err := document.view.Effective.WriteEffective(&native); err != nil {
|
||||
return showFailure(err, diagnostics, written)
|
||||
}
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return showFailure(err, diagnostics, written)
|
||||
}
|
||||
if index > 0 && hasYAMLDirective(native.Bytes()) {
|
||||
if err := writeReport(invocation.Streams.Out, []byte("...\n")); err != nil {
|
||||
outcome := showFailure(err, diagnostics, true)
|
||||
|
||||
Reference in New Issue
Block a user