Uh oh!
There was an error while loading. Please reload this page.
serialize: use Result - #13107
Conversation
huonw
commented
Mar 24, 2014
Yay! ❤️ The next person to take a snapshot will get to have fun with (Also, this needs a rebase.) |
seanmonstar
commented
Mar 24, 2014
Rebase already? Hah, I rebased just before submitting :-) |
erickt
commented
Mar 24, 2014
This is great work. Once this clears travis, r=me. |
huonw
commented
Mar 24, 2014
(cc @wycats: a magical @seanmonstar fixed all/some of your problems for you.) |
alexcrichton
commented
Mar 24, 2014
I'm a little worried about the explosion of generics when dealing with serialization things. Dealing with decodable/encodable already has a few type parameters which makes signatures a bit unwieldy, and adding another for an error seems a little sad. Is it crucial that all encoders/decoders need their own error type? Could this all possibly return |
wycats
commented
Mar 24, 2014
My decoders definitely want their own Error type. I think this is just a side effect of not having yet nailed down the expected patterns for Result propagation. |
seanmonstar
commented
Mar 24, 2014
There is definitely errors that could occur besides IoError. Take this example: #[deriving(Decodable)]structBar{foo:uint}let json_str = "{\"foo\":false}";// assume we've merged Parser and Decoder (a future PR)let decoder = json::Decoder::from_str(json_str);let bar = matchDecodable::decode(decoder){Ok(b) => b,Err(e) => fail!("{}", e)};This isn't an IoError. With Encoders, it's certainly possible that they could only return enumFoo{Bar(~str, ~str)}impl<D:Decoder,E>Decodable<D,E>forFoo{fndecode(&self,d:&mutD) -> Result<(),E>{match*self{Bar(ref a,ref b) => {// i forget to use `emit_enum_variant`
d.emit_enum(|d| {
try!(d.emit_enum_variant_arg(0, |d| d.emit_str(a)));
d.emit_enum_variant_arg(1, |d| d.emit_str(b))})}}}}A Decoder could be keeping track of a state, and notice that you emitted values wrongly, and return some @erickt As for Travis: it seems it failed downloading llvm dependencies? Can anyone give it a kick? |
alexcrichton
commented
Mar 24, 2014
I kicked off the relevant travis build, and it sounds like custom errors is necessary. Thanks for the explanation! |
seanmonstar
commented
Mar 24, 2014
Oh wow, I somehow missed a bunch of encode stuff in rustc/metadata. Working on it... |
seanmonstar
commented
Mar 26, 2014
there we go, had missed a bunch of in rustc/middle/astencode as well. Sorry for the |
seanmonstar
commented
Mar 26, 2014
@erickt r? |
There was a problem hiding this comment.
You should do krate.encode(&mut json).unwrap() here, so we'll fail instead of silently ignoring an error.
There was a problem hiding this comment.
this was just to remove the unused result warning, because stage0 has it returning (). I could add in the staged unwrap_ functions here as well.
erickt
commented
Mar 27, 2014
Epic work. r=me with my minor comments addressed. |
seanmonstar
commented
Mar 27, 2014
@erickt just force pushed up all the FIXMEs and an unwrap_ in rustc/driver. |
seanmonstar
commented
Mar 27, 2014
@erickt i had missed a doc example, I've fixed and ran them locally to be sure. |
All of Decoder and Encoder's methods now return a Result. Encodable.encode() and Decodable.decode() return a Result as well. fixesrust-lang#12292
seanmonstar
commented
Mar 28, 2014
something else landed before bors got to this, requiring another rebase against master. |
All of Decoder and Encoder's methods now return a Result. Encodable.encode() and Decodable.decode() return a Result as well. fixes#12292
All of Decoder and Encoder's methods now return a Result.
Encodable.encode() and Decodable.decode() return a Result as well.
fixes#12292