<wwalker>
OK, I want to do code like this: doc.first_element_child.first_element_child.other_xml_method.another_xml_method # But that results in this error,
<wwalker>
Error: undefined method 'first_element_child' for Nil (compile-time type is (XML::Node | Nil))
<FromGitter>
<Blacksmoke16> Probably need to ensure there is a first child on the doc
<FromGitter>
<Blacksmoke16> I.e. handle the case it returns nil
<wwalker>
Is there any nice clean way to tell it "yes, just do it and fail at run time if the data is bad" rather than having to do each method call and verify each return is "not nil?" ?
<wwalker>
@Blacksmoke16 this is at compile time, not run time. I know that the nodes will exist.
<FromGitter>
<Blacksmoke16> If you are 100% sure, you can use `.not_nil!`
<wwalker>
I tried wrappign it in a begin...rescue, but it still refuses to compile
<FromGitter>
<Blacksmoke16> That only rescues runtime exceptions. You need to do something to prove that the value isn't nil
<FromGitter>
<Blacksmoke16> E.g. conditional logic, use .try, etc
<FromGitter>
<Blacksmoke16> Prove to the compiler*
<wwalker>
@Blacksmoke16 thank you! That worked great. In the rare condition that the inbound xml is bad, I'm okay with a runtime error.
<FromGitter>
<Blacksmoke16> Should ideally still gracefully handle it, but:shrug:
<wwalker>
Yes, but since it is xml, there will be like 6 of those calls, and 6 nested if statements is just ugly.
<FromGitter>
<Blacksmoke16> Xpath it?
<wwalker>
which shard? I tried to use naqvis/crystal-xpath2 but gave up because I can't figure out how to just read in xml with it. "refer to spec for usage examples" The spec seems to only build the document 1 element at a time.
<FromGitter>
<Blacksmoke16> No shard, it's built into the stdlib
<wwalker>
I started with 'require "xml"' and that loads and all, how do I do an xpath with it?
<wwalker>
may have found it...
<wwalker>
Yep, Thank you!
<FromGitter>
<Blacksmoke16> 👍
Sankalp has quit [Ping timeout: 246 seconds]
Sankalp has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
ur5us has joined #crystal-lang
lanodan has quit [Read error: Software caused connection abort]
taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
taupiqueur has quit [*.net *.split]
jmdaemon has quit [Ping timeout: 255 seconds]
<Ober>
xml is soo evil
walez___ has quit [Ping timeout: 255 seconds]
<FromGitter>
<naqvis> > *<wwalker>* which shard? I tried to use naqvis/crystal-xpath2 but gave up because I can't figure out how to just read in xml with it. "refer to spec for usage examples" The spec seems to only build the document 1 element at a time. ⏎ ⏎ Seems shard README and/or documentation isn't good enough to explain the use-case of that shard. That shard implements the `xpath2` and is designed to be used by