Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5] Added safety check for loading .env and .env-example #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions lib/dotenvious/loaders/environment.rb
@@ -1,3 +1,5 @@
require_relative "../errors"

module Dotenvious
module Loaders
class Environment
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions lib/dotenvious/loaders/environments.rb
Expand Up @@ -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
Expand Down