Commit module changes only after successful execution
This commit is contained in:
51
internal/framework/runner/failure.go
Normal file
51
internal/framework/runner/failure.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
||||
)
|
||||
|
||||
// ExecutionFailure associates the initiating cause with its processing owner.
|
||||
// The section is optional, for example when module setup fails.
|
||||
type ExecutionFailure struct {
|
||||
Phase string
|
||||
Origin *outcomes.Reference
|
||||
HasSection bool
|
||||
Cause error
|
||||
}
|
||||
|
||||
func (f *ExecutionFailure) Error() string { return f.Cause.Error() }
|
||||
func (f *ExecutionFailure) Unwrap() error { return f.Cause }
|
||||
|
||||
func locateFailure(cause error, phase string, origin outcomes.Reference, hasSection bool, operations []outcomes.Operation) *ExecutionFailure {
|
||||
for _, operation := range operations {
|
||||
if operation.Cause == nil || !errors.Is(cause, operation.Cause) {
|
||||
continue
|
||||
}
|
||||
ref := operation.Reference
|
||||
if ref.StageIndex == nil {
|
||||
ref.StageIndex, ref.StageID = origin.StageIndex, origin.StageID
|
||||
}
|
||||
if ref.ProposalIndex == nil {
|
||||
ref.ProposalIndex = origin.ProposalIndex
|
||||
}
|
||||
if ref.RepairAttempt == nil {
|
||||
ref.RepairAttempt = origin.RepairAttempt
|
||||
}
|
||||
return &ExecutionFailure{Phase: phase, Origin: &ref, HasSection: hasSection, Cause: cause}
|
||||
}
|
||||
return &ExecutionFailure{Phase: phase, Origin: &origin, HasSection: hasSection, Cause: cause}
|
||||
}
|
||||
|
||||
func failureReference(spec contracts.ModuleRunSpec, section *int, kind outcomes.OperationKind) outcomes.Reference {
|
||||
ref := outcomes.Reference{
|
||||
StageIndex: &spec.Index, StageID: spec.ID,
|
||||
ModuleKey: spec.ModuleKey, ModuleInstance: spec.InstanceName, Kind: kind,
|
||||
}
|
||||
if section != nil {
|
||||
ref.SectionIndex = *section
|
||||
}
|
||||
return ref
|
||||
}
|
||||
Reference in New Issue
Block a user