digitalmars.D.learn - Orange check failling all of a sudden
- DigitalDesigns (53/53) Jun 11 2018 Changed some things in my app but unrelated to serialization and
- DigitalDesigns (29/29) Jun 11 2018 and if I completely remove the check then everything works fine.
- DigitalDesigns (7/7) Jun 11 2018 I also get a lot of inout's attached to key names. Seems
- Jacob Carlborg (4/9) Jun 19 2018 I don't think they're technically necessary.
- DigitalDesigns (11/11) Jun 12 2018 Also, is there any way to have a field as optional? Right now
- Jacob Carlborg (11/21) Jun 19 2018 The only way would be to implement the serialization yourself, i.e.
- Jacob Carlborg (5/57) Jun 19 2018 The XML parts all come from the standard library, slightly tweaked. Can
Changed some things in my app but unrelated to serialization and now my app fails when trying to read the xml that was generated at the output of the previous run. Where it is failing is here: void checkSpace(ref string s) safe pure // rule 3 { import std.algorithm.searching : countUntil; import std.ascii : isWhite; import std.utf : byCodeUnit; mixin Check!("Whitespace"); ptrdiff_t i = s.byCodeUnit.countUntil!(a => !isWhite(a)); if (i == -1 && s.length > 0 && isWhite(s[0])) s = s[$ .. $]; else if (i > -1) s = s[i .. $]; if (s is old) fail(); } s = ="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> Actual xml data(first 3 lines): <?xml version="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> It seems odd that it should fail when munching whitespace. It seems that the checker is getting off to a bad start from the get go. - [orange.xml.PhobosXml.CheckException] 0x03135880 {err=0x00000000, tail="="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> orange.xml.PhobosXml.CheckException + orange.xml.PhobosXml.XMLException 0x03135880 {} orange.xml.PhobosXml.XMLException err 0x00000000 orange.xml.PhobosXml.CheckException + tail "="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> ... const(char)[] + msg "Whitespace" const(char)[] line 0 uint column 0 uint This was all working fine before and I'm not sure how it broke. The xmllint shows the xml is well formed so this is buggy code. Note that if I also remove all the xml inside data then the same error occurs, so this is my xml: <?xml version="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> </data> </archive> that still fails when checking whitespace.
Jun 11 2018
and if I completely remove the check then everything works fine. */ class DocumentParser : ElementParser { string xmlText; /** * Constructs a DocumentParser. * * The input to this function MUST be valid XML. * This is enforced by the function's in contract. * * Params: * xmlText_ = the entire XML document as text * */ this(string xmlText_) in { assert(xmlText_.length != 0); try { // Confirm that the input is valid XML //check(xmlText_); // COMMENTED OUT! } catch (CheckException e) { // And if it's not, tell the user why not assert(false, "\n" ~ e.toString()); }
Jun 11 2018
I also get a lot of inout's attached to key names. Seems excessive but inout(inout(double)[]) <array id="31" type="inout(inout(double)[])" length="0" key="map" /> <struct type="inout(X)" id="32" key="info"> Maybe they are necessary but seems like they are redundant.
Jun 11 2018
On 2018-06-12 02:13, DigitalDesigns wrote:I also get a lot of inout's attached to key names. Seems excessive but inout(inout(double)[]) <array id="31" type="inout(inout(double)[])" length="0" key="map" /> <struct type="inout(X)" id="32" key="info"> Maybe they are necessary but seems like they are redundant.I don't think they're technically necessary. -- /Jacob Carlborg
Jun 19 2018
Also, is there any way to have a field as optional? Right now when I update a filed in a serialized type the app crashes because it can't find the field in the serialized data(since it was just added in the code). This requires either regenerating the data or manually adding the serialized field to each entry... both are impractical. It would be nice to disable missing fields from throwing. While I could catch one error it would be a pain to try and catch an arbitrary number of them. Maybe an attribute is better used: allowDefaultSerialized
Jun 12 2018
On 2018-06-13 02:31, DigitalDesigns wrote:Also, is there any way to have a field as optional? Right now when I update a filed in a serialized type the app crashes because it can't find the field in the serialized data(since it was just added in the code). This requires either regenerating the data or manually adding the serialized field to each entry... both are impractical.The only way would be to implement the serialization yourself, i.e. implement `toData` and `fromData`, but I don't think there's a way to check if a field is present in the serialized data. So it might not be so easy.It would be nice to disable missing fields from throwing. While I could catch one error it would be a pain to try and catch an arbitrary number of them.You can set the "errorCallback" [1] to an empty delegate or whatever you see fit. But this callback will be called for other errors as well.Maybe an attribute is better used: allowDefaultSerialized[1] https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L133 -- /Jacob Carlborg
Jun 19 2018
On 2018-06-11 20:00, DigitalDesigns wrote:Changed some things in my app but unrelated to serialization and now my app fails when trying to read the xml that was generated at the output of the previous run. Where it is failing is here: void checkSpace(ref string s) safe pure // rule 3 { import std.algorithm.searching : countUntil; import std.ascii : isWhite; import std.utf : byCodeUnit; mixin Check!("Whitespace"); ptrdiff_t i = s.byCodeUnit.countUntil!(a => !isWhite(a)); if (i == -1 && s.length > 0 && isWhite(s[0])) s = s[$ .. $]; else if (i > -1) s = s[i .. $]; if (s is old) fail(); } s = ="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> Actual xml data(first 3 lines): <?xml version="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> It seems odd that it should fail when munching whitespace. It seems that the checker is getting off to a bad start from the get go. - [orange.xml.PhobosXml.CheckException] 0x03135880 {err=0x00000000, tail="="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> orange.xml.PhobosXml.CheckException + orange.xml.PhobosXml.XMLException 0x03135880 {} orange.xml.PhobosXml.XMLException err 0x00000000 orange.xml.PhobosXml.CheckException + tail "="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> ... const(char)[] + msg "Whitespace" const(char)[] line 0 uint column 0 uint This was all working fine before and I'm not sure how it broke. The xmllint shows the xml is well formed so this is buggy code. Note that if I also remove all the xml inside data then the same error occurs, so this is my xml: <?xml version="1.0" encoding="UTF-8"?> <archive version="1.0.0" type="org.dsource.orange.xml"> <data> </data> </archive> that still fails when checking whitespace.The XML parts all come from the standard library, slightly tweaked. Can you please check if std.xml has the same problem? -- /Jacob Carlborg
Jun 19 2018