allow channel marshaler to return errors from cmds.Response
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Sep 4, 2015 at 14:12 UTC
206739d10cd9683c27f96ec48de62f81d12d4a18
7 files changed
+15
commands/channelmarshaler.go
+5
@@ -5,6 +5,7 @@ import "io"
5
type ChannelMarshaler struct {
6
Channel <-chan interface{}
7
Marshaler func(interface{}) (io.Reader, error)
8
+ Res Response
9
10
reader io.Reader
11
}
@@ -13,6 +14,10 @@ func (cr *ChannelMarshaler) Read(p []byte) (int, error) {
14
if cr.reader == nil {
15
val, more := <-cr.Channel
16
if !more {
17
+ //check error in response
18
+ if cr.Res.Error() != nil {
19
+ return 0, cr.Res.Error()
20
+ }
21
return 0, io.EOF
22
}
23
commands/response.go
+1
@@ -57,6 +57,7 @@ var marshallers = map[EncodingType]Marshaler{
57
return &ChannelMarshaler{
58
Channel: ch,
59
Marshaler: marshalJson,
60
+ Res: res,
61
}, nil
62
}
63
core/commands/dht.go
+5
@@ -131,6 +131,7 @@ var queryDhtCmd = &cmds.Command{
131
return &cmds.ChannelMarshaler{
132
Channel: outChan,
133
Marshaler: marshal,
134
+ Res: res,
135
}, nil
136
},
137
},
@@ -249,6 +250,7 @@ FindProviders will return a list of peers who are able to provide the value requ
250
return &cmds.ChannelMarshaler{
251
Channel: outChan,
252
Marshaler: marshal,
253
+ Res: res,
254
}, nil
255
},
256
},
@@ -354,6 +356,7 @@ var findPeerDhtCmd = &cmds.Command{
356
return &cmds.ChannelMarshaler{
357
Channel: outChan,
358
Marshaler: marshal,
359
+ Res: res,
360
}, nil
361
},
362
},
@@ -461,6 +464,7 @@ GetValue will return the value stored in the dht at the given key.
464
return &cmds.ChannelMarshaler{
465
Channel: outChan,
466
Marshaler: marshal,
467
+ Res: res,
468
}, nil
469
},
470
},
@@ -571,6 +575,7 @@ PutValue will store the given key value pair in the dht.
575
return &cmds.ChannelMarshaler{
576
Channel: outChan,
577
Marshaler: marshal,
578
+ Res: res,
579
}, nil
580
},
581
},
core/commands/ping.go
+1
@@ -71,6 +71,7 @@ trip latency information.
71
return &cmds.ChannelMarshaler{
72
Channel: outChan,
73
Marshaler: marshal,
74
+ Res: res,
75
}, nil
76
},
77
},
core/commands/refs.go
+1
@@ -141,6 +141,7 @@ Note: list all refs recursively with -r.
141
return &cmds.ChannelMarshaler{
142
Channel: outChan,
143
Marshaler: marshal,
144
+ Res: res,
145
}, nil
146
},
147
},
core/commands/repo.go
+1
@@ -90,6 +90,7 @@ order to reclaim hard disk space.
90
return &cmds.ChannelMarshaler{
91
Channel: outChan,
92
Marshaler: marshal,
93
+ Res: res,
94
}, nil
95
},
96
},
core/commands/stat.go
+1
@@ -167,6 +167,7 @@ var statBwCmd = &cmds.Command{
167
return &cmds.ChannelMarshaler{
168
Channel: outCh,
169
Marshaler: marshal,
170
+ Res: res,
171
}, nil
172
},
173
},