Method: ChefAPI::Util#safe_read
- Defined in:
- lib/chef-api/util.rb
#safe_read(path) ⇒ Array<String>
“Safely” read the contents of a file on disk, catching any permission errors or not found errors and raising a nicer exception.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/chef-api/util.rb', line 78 def safe_read(path) path = File.(path) name = File.basename(path, '.*') contents = File.read(path) [name, contents] rescue Errno::EACCES raise Error::InsufficientFilePermissions.new(path: path) rescue Errno::ENOENT raise Error::FileNotFound.new(path: path) end |