[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Code for discussion: broker plugin loading




----- Original Message -----
> 
> 
> ----- Original Message -----
> > From: "Clayton Coleman" <ccoleman redhat com>
> > 
> > On Jul 29, 2013, at 7:52 PM, Luke Meyer <lmeyer redhat com> wrote:
> > 
> > > See, you would expect stderr to go to the apache log, but it seems
> > > that Bundler just totally swallows it. And on the command line
> > > it's even worse. I added a bogus conf file and under the code I
> > > gave, this is (still) the result:
> > > 
> > > # bundle exec rails console
> > > Could not find gem 'ahfasdfasdfsdkfk (>= 0) ruby' in the gems
> > > available on this machine.
> > > Run `bundle install` to install missing gems.
> > > # oo-admin-ctl-district
> > > Could not find gem 'ahfasdfasdfsdkfk (>= 0) ruby' in the gems
> > > available on this machine.
> > > Run `bundle install` to install missing gems.
> > > 
> > > ... which is really, *really* not the advice we want to give
> > > people. I guess Bundler is mocking gem or something. Is there any
> > > way to modify what Bundler does with errors?
> > 
> > I am shocked its not going to stdout/stderr, but remember its managed
> > by the service script.  Possibly we're missing a redirect there?
> 
> This is CLI, service script is not in play. That said...
> 
> Turns out I'm utterly wrong about $stderr being swallowed. It's just not
> getting generated. I was assuming that when Gemfile trying to load a gem
> failed, there would be some kind of exception. Instead, apparently Bundler
> just registers that as a failure and fails later.
> 
> I tracked it down to boot.rb which is where bundler is normally loaded
> ("bundle exec ..." doesn't get to this but scripts and service do). I
> surrounded the bundler setup like so:
> 
> begin
>   captured = StringIO.new
>   previous_stderr, previous_stdout, $stderr, $stdout = $stderr, $stdout,
>   captured, captured
>   require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
> rescue Exception
>   $stderr, $stdout = previous_stderr, previous_stdout
>   $stderr.puts "Error while loading bundler. Bundler said:", captured.string
>   $stderr.puts "But don't do that!"
>   raise
> ensure
>   $stderr, $stdout = previous_stderr, previous_stdout
> end
> 
> 
> ... which results in e.g.:
> # oo-admin-ctl-district
> Error while loading bundler. Bundler said:
> Could not find gem 'o-o-akjsdfhklajsdf (>= 0) ruby' in the gems available on
> this machine.
> Run `bundle install` to install missing gems.
> But don't do that!
> 
> 
> 
> Meaning, we can at least capture and rephrase what bundler says, although I
> don't see any way to do this at the Gemfile level. Might be nice to have an
> "optional" parameter on gem so that if it fails, bundler just kind of
> complains and keeps going, but I'm thinking the bundler maintainers would
> frown on that.
> 
> The exception, BTW, is System::Exit.
> 
> So is this what we would like to do?
> 

Could we not simply rescue and rethrow our own exception with a message?  That guarantees it's shown last.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]