mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-11 15:15:58 +08:00
allow channel marshaler to return errors from cmds.Response
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -5,6 +5,7 @@ import "io"
|
||||
type ChannelMarshaler struct {
|
||||
Channel <-chan interface{}
|
||||
Marshaler func(interface{}) (io.Reader, error)
|
||||
Res Response
|
||||
|
||||
reader io.Reader
|
||||
}
|
||||
@ -13,6 +14,10 @@ func (cr *ChannelMarshaler) Read(p []byte) (int, error) {
|
||||
if cr.reader == nil {
|
||||
val, more := <-cr.Channel
|
||||
if !more {
|
||||
//check error in response
|
||||
if cr.Res.Error() != nil {
|
||||
return 0, cr.Res.Error()
|
||||
}
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ var marshallers = map[EncodingType]Marshaler{
|
||||
return &ChannelMarshaler{
|
||||
Channel: ch,
|
||||
Marshaler: marshalJson,
|
||||
Res: res,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user