diff --git a/lib/dotenvious/errors.rb b/lib/dotenvious/errors.rb new file mode 100644 index 0000000..2b98ca4 --- /dev/null +++ b/lib/dotenvious/errors.rb @@ -0,0 +1,9 @@ +module Dotenvious + class FileNotFoundError < ArgumentError + attr_reader :file + def initialize(filename) + @file = filename + super + end + end +end diff --git a/lib/dotenvious/loaders/environment.rb b/lib/dotenvious/loaders/environment.rb index 33e5574..d8a0709 100644 --- a/lib/dotenvious/loaders/environment.rb +++ b/lib/dotenvious/loaders/environment.rb @@ -1,3 +1,5 @@ +require_relative "../errors" + module Dotenvious module Loaders class Environment @@ -19,6 +21,9 @@ def filename end def file + if !File.exist?(filename) + raise Dotenvious::FileNotFoundError.new(filename) + end File.read(filename).split("\n") end end diff --git a/lib/dotenvious/loaders/environments.rb b/lib/dotenvious/loaders/environments.rb index b56a867..bcce42c 100644 --- a/lib/dotenvious/loaders/environments.rb +++ b/lib/dotenvious/loaders/environments.rb @@ -5,8 +5,16 @@ module Dotenvious module Loaders class Environments def load_envs - Env.new.load - Example.new.load + begin + Env.new.load + rescue Dotenvious::FileNotFoundError => ex + STDERR.puts "#{ex.file} not found" + end + begin + Example.new.load + rescue Dotenvious::FileNotFoundError => ex + STDERR.puts "#{ex.file} not found" + end end end end