1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-23 21:47:52 +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:
Jeromy
2015-09-04 14:12:19 -07:00
parent 93e9f8418b
commit 206739d10c
7 changed files with 15 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import "io"
type ChannelMarshaler struct { type ChannelMarshaler struct {
Channel <-chan interface{} Channel <-chan interface{}
Marshaler func(interface{}) (io.Reader, error) Marshaler func(interface{}) (io.Reader, error)
Res Response
reader io.Reader reader io.Reader
} }
@ -13,6 +14,10 @@ func (cr *ChannelMarshaler) Read(p []byte) (int, error) {
if cr.reader == nil { if cr.reader == nil {
val, more := <-cr.Channel val, more := <-cr.Channel
if !more { if !more {
//check error in response
if cr.Res.Error() != nil {
return 0, cr.Res.Error()
}
return 0, io.EOF return 0, io.EOF
} }

View File

@ -57,6 +57,7 @@ var marshallers = map[EncodingType]Marshaler{
return &ChannelMarshaler{ return &ChannelMarshaler{
Channel: ch, Channel: ch,
Marshaler: marshalJson, Marshaler: marshalJson,
Res: res,
}, nil }, nil
} }

View File

@ -131,6 +131,7 @@ var queryDhtCmd = &cmds.Command{
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outChan, Channel: outChan,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },
@ -249,6 +250,7 @@ FindProviders will return a list of peers who are able to provide the value requ
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outChan, Channel: outChan,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },
@ -354,6 +356,7 @@ var findPeerDhtCmd = &cmds.Command{
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outChan, Channel: outChan,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },
@ -461,6 +464,7 @@ GetValue will return the value stored in the dht at the given key.
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outChan, Channel: outChan,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },
@ -571,6 +575,7 @@ PutValue will store the given key value pair in the dht.
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outChan, Channel: outChan,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },

View File

@ -71,6 +71,7 @@ trip latency information.
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outChan, Channel: outChan,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },

View File

@ -141,6 +141,7 @@ Note: list all refs recursively with -r.
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outChan, Channel: outChan,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },

View File

@ -90,6 +90,7 @@ order to reclaim hard disk space.
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outChan, Channel: outChan,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },

View File

@ -167,6 +167,7 @@ var statBwCmd = &cmds.Command{
return &cmds.ChannelMarshaler{ return &cmds.ChannelMarshaler{
Channel: outCh, Channel: outCh,
Marshaler: marshal, Marshaler: marshal,
Res: res,
}, nil }, nil
}, },
}, },