you need to check for the presence of each env var before this point. Then
you can just display one error, which talks about how to resolve the
problem rather than just telling you that there is one.

Ie:
class MissingAwsConfigError < StandardError
  def initialize(vars)
    @vars = vars
  end
  def to_s
    "The following vars have not been set in your ENV #{@vars.join(',')}.
You need to setup an AWS bucket with the following permissions and stuff"
  end
end

Then at the top of the initialize method do:

if !missing_env_vars.empty?
  raise MissingAwsConfigError.new(missing_env_vars)
end




On Tue, Feb 11, 2014 at 6:22 PM, john irving <notifications@github.com>wrote:

> In app/helpers/upload_helper.rb:
>
> > @@ -12,9 +12,9 @@ class S3Uploader
> >      def initialize(options)
> >        @options = options.reverse_merge(
> >          id: "fileupload",
> > -        aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
> > -        aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
> > -        bucket: ENV['AWS_ATTACHMENTS_BUCKET'],
> > +        aws_access_key_id:     ENV.fetch('AWS_ACCESS_KEY_ID'),
> > +        aws_secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
> > +        bucket:                ENV.fetch('AWS_ATTACHMENTS_BUCKET'),
>
> i played with writing my own error message but couldn't find a way to make
> it dry. Missing code theory.
>
> i had
>
>         aws_access_key_id:        ENV.fetch('AWS_ACCESS_KEY_ID')  { |key|  raise "you must set ENV[:#{key}] },        aws_secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY')  { |key|  raise "you must set ENV[:#{key}] },
>         bucket:                             ENV.fetch('AWS_ATTACHMENTS_BUCKET')  { |key|  raise "you must set ENV[:#{key}] }
>
> and i think this worked
>
> then tried to dry it up like in confident ruby like:
>
>        ENV_WARNING = -> { |key| raise("You must define ENV[:#{key}]") }
>
>        ...
>        aws_access_key_id:        ENV.fetch('AWS_ACCESS_KEY_ID', &ENV_WARNING),
>        aws_secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', &ENV_WARNING),
>        bucket:                             ENV.fetch('AWS_ATTACHMENTS_BUCKET', &ENV_WARNING)
>
> but i don't know enough about Procs .... or what & does
> be interested to know what i should read to understand that better
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/loomio/loomio/pull/1270/files#r9613985>
> .
>