Skip to content

[Feature Request] Tolerate missing values #11

@BigBoyBarney

Description

@BigBoyBarney

Hi!

I haven't actively used the shard since I finished implementing my config file reader a few months ago, but I recently started a new project so I had to write a new one :P

It still works very well 🥳 Thank you!

The issue I ran into, however, was that migrating config files is impossible, because missing nodes will throw an error:

require "kdl"

class Missing
  include ::KDL::Serializable

  @[KDL::Child(name: "Something", unwrap: "argument")]
  property something : String = "hello!"
end

kdl = KDL.load_file "test.kdl"
missing = Missing.from_kdl kdl
pp missing

Trying to run this on an existing, but empty test.kdl file will results in the following error:

Unhandled exception: Element not found (Enumerable::NotFoundError)
  from lib/kdl/src/kdl/node.cr:70:28 in 'child'
  from lib/kdl/src/kdl/node.cr:98:7 in 'arg'
  from lib/kdl/src/kdl/serializable.cr:86:7 in 'initialize:__node_for_kdl_serializable'
  from test.cr:4:3 in 'new_from_kdl_node'
  from test.cr:4:3 in 'new'
  from test.cr:4:3 in 'from_kdl'
  from test.cr:11:1 in '__crystal_main'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions