Skip to content

no exception if file doesn't exist #137

@bastelfreak

Description

@bastelfreak

Describe the Bug

I'm currently writing a Puppet function that relies on Hocon. I noticed that Hocon can parse files but it will return an empty hash if the provided file doesn't exist:

root@puppet ~ # /opt/puppetlabs/puppet/bin/irb
irb(main):001:0> require 'hocon'
=> true
irb(main):002:0> Hocon.load('/tmp/foo.conwf')
/opt/puppetlabs/puppet/lib/ruby/vendor_gems/gems/hocon-1.4.0/lib/hocon.rb:23:in `load': Unrecognized file extension '.conwf' and no value provided for :syntax option (Hocon::ConfigError::ConfigParseError)
	from (irb):2:in `<main>'
	from /opt/puppetlabs/puppet/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
	from /opt/puppetlabs/puppet/bin/irb:25:in `load'
	from /opt/puppetlabs/puppet/bin/irb:25:in `<main>'
irb(main):003:0> Hocon.load('/tmp/foow.conf')
=> {}
irb(main):004:0>
root@puppet ~ # ls -la /tmp/foow.conf
ls: cannot access '/tmp/foow.conf': No such file or directory
root@puppet ~ #

Expected Behavior

The Hocon gem should raise an exception if a file is not found / is not readable. Now you cannot determine if the file doesn't exist or contains an empty hash.

Steps to Reproduce

  • require 'hocon'
  • Hocon.load('/non/existing/path')

Environment


*** LOCAL GEMS ***

hocon (1.4.0)
    Authors: Chris Price, Wayne Warren, Preben Ingvaldsen, Joe
    Pinsonault, Kevin Corcoran, Jane Lu
    Homepage: https://github.com/puppetlabs/ruby-hocon
    License: Apache License, v2
    Installed at: /opt/puppetlabs/puppet/lib/ruby/vendor_gems

    HOCON Config Library
root@puppet ~ #

Additional Context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions