Closed ctm closed 2 weeks ago
Heh. This has already pointed out a bug that's been there since day one but nobody has ever reported. If you start writing a comment and then change your mind and delete it, the last text that was present in the input box is kept due to the fact that the comment box uses assigned_mapped
and assign_mapped
isn't built to work with Option<String>
, because it takes None
to mean "can't parse; ignore". That's my fault for using an Option<T>
instead of a Result<T, ()>
.
For anyone reading (probably just Ed, although perhaps I'll re-read this in order to write an article or to give a talk), the issue is that I created a helper function assign_mapped
whose purpose is to update a field, but only if the contents parses into something reasonable. Not being able to parse isn't an error, per-se, because someone might be typing something that will become reasonable with a few more characters, so we don't want to discard the input prematurely. So, my new-to-rust brain thought "if we're detecting something we don't want and that's all we know, we want it or not, use Option
to represent wanted or not." The problem is that a comment itself is an Option
, because we're going to store in a database where we'd like non-present values to be represented as NULL
, rather than the zero-length string.
It's perfectly fine to wrap an Option
in an Option
and in fact, my quick soloution is to simply do that. The bug was my code for processing a comment was returning None
when it detected the zero-lengthy string, when it should have returned Some(None)
. So assign_mapped
saw the None
and decided the change that was made to the input field was transitory and shouldn't have been captured, rather than the player has chosen not to include a comment. Rust didn't detect my programming error, because what I wrote semantically made sense, but there were no type-level differences to prompt Rust into letting me know that what I had written isn't what I wanted.
I don't think this insight is particularly valuable to anybody who is experienced in Rust, but if I were to start up a Rust programmer's group in Albuquerque, like I did for RubiABQ, or if I were to give a super quick "why Rust is so awesome" talk at BARGE, it might be a good footnote as an example of a Rust program that compiled but didn't work on the first try.
Whee!
Other than what remains of my original unfinished work (#1439), I got everything done here except adding any additional info when extra_detail
is set. I'm deploying now.
Done. Deploying now.
Fix the following issues I'm seeing as I do more testing of structure sheets and templates.
This is a catch-all GitHub issue for smallish stuff that might easily fall through the cracks. I will probably do some of the easiest ones first, since they're just a matter of adding a line or two of code and then testing.
SomethingChanged
handler forSynchronized Breaks(not needed after all)oninput
handlers for