package runner import ( "errors" "gitea.maximumdirect.net/eric/audita/v4/internal/framework/contracts" "gitea.maximumdirect.net/eric/audita/v4/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 }