Inline error type checks in agent-run handler
Drop the isType helper that merely discarded the value already returned by errors.AsType and inline the suspend and interrupt checks directly into the result-handling branch. Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
@@ -197,16 +197,13 @@ func (h *handler) executeRun(ctx context.Context, run *coredata.AgentRun) error
|
|||||||
// interruption parks it in AWAITING_APPROVAL until an approval
|
// interruption parks it in AWAITING_APPROVAL until an approval
|
||||||
// decision requeues it. Anything else is a genuine failure.
|
// decision requeues it. Anything else is a genuine failure.
|
||||||
if runErr != nil {
|
if runErr != nil {
|
||||||
switch {
|
if _, ok := errors.AsType[*agent.SuspendedError](runErr); ok {
|
||||||
case isType[*agent.SuspendedError](runErr):
|
|
||||||
run.Status = coredata.AgentRunStatusPending
|
run.Status = coredata.AgentRunStatusPending
|
||||||
runErr = nil
|
runErr = nil
|
||||||
|
} else if _, ok := errors.AsType[*agent.InterruptedError](runErr); ok {
|
||||||
case isType[*agent.InterruptedError](runErr):
|
|
||||||
run.Status = coredata.AgentRunStatusAwaitingApproval
|
run.Status = coredata.AgentRunStatusAwaitingApproval
|
||||||
runErr = nil
|
runErr = nil
|
||||||
|
} else {
|
||||||
default:
|
|
||||||
run.Status = coredata.AgentRunStatusFailed
|
run.Status = coredata.AgentRunStatusFailed
|
||||||
run.Result = nil
|
run.Result = nil
|
||||||
|
|
||||||
@@ -257,9 +254,3 @@ func (h *handler) executeRun(ctx context.Context, run *coredata.AgentRun) error
|
|||||||
|
|
||||||
return runErr
|
return runErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func isType[T error](err error) bool {
|
|
||||||
_, ok := errors.AsType[T](err)
|
|
||||||
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user