Skip to content

Commit

Permalink
return an error instead of panicking when failing to get edge
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed Sep 28, 2021
1 parent e839ff7 commit ae8af5c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions solver/internal/pipe/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,34 @@ func (pr *receiver) Cancel() {
func (pr *receiver) Status() Status {
return pr.status
}

type erroredPipe struct {
req interface{}
err error
}

func NewErroredPipe(req interface{}, err error) Receiver {
return &erroredPipe{
req: req,
err: err,
}
}

func (p *erroredPipe) Request() interface{} {
return p.req
}

func (p *erroredPipe) Receive() bool {
return true
}

func (p *erroredPipe) Status() Status {
return Status{
Canceled: false,
Completed: true,
Err: p.err,
Value: nil,
}
}

func (p *erroredPipe) Cancel() {}
3 changes: 2 additions & 1 deletion solver/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package solver

import (
"context"
"fmt"
"os"
"sync"

Expand Down Expand Up @@ -351,7 +352,7 @@ type pipeFactory struct {
func (pf *pipeFactory) NewInputRequest(ee Edge, req *edgeRequest) pipe.Receiver {
target := pf.s.ef.getEdge(ee)
if target == nil {
panic("failed to get edge") // TODO: return errored pipe
return pipe.NewErroredPipe(req, fmt.Errorf("failed to get edge"))
}
p := pf.s.newPipe(target, pf.e, pipe.Request{Payload: req})
if debugScheduler {
Expand Down

0 comments on commit ae8af5c

Please sign in to comment.