unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / Atom feed
* using pp without require 'pp' when $DEBUG = True
@ 2017-11-16  0:57 Robinson Jr, James P (Jim)      HHHH
  2017-11-16  1:30 ` Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Robinson Jr, James P (Jim)      HHHH @ 2017-11-16  0:57 UTC (permalink / raw)
  To: unicorn-public

Hello, 
 	I am not usually a ruby developer, and I just recently stumbled across
an odd bug, that only someone who  didn¹t know what they were doing would
stumble across.  I am honestly not sure if this really counts as a bug,
but I thought I should let you know.

unicorn/lib/unicorn.rb line 62 is:

      pp({ :inner_app => inner_app }) if $DEBUG

Nowhere in the file is there require Œpp¹

This is not an issue if you run "unicorn -d config.ru², but If you
manually set $DEBUG = true,  which I foolishly did because I didn¹t
realize that $DEBUG was a special variable in ruby,  you get an undefined
method error.   


I will be changing my code to use a different variable name, however I am
not sure if there are valid reasons to manually set $DEBUG in ruby.  If
there are, this may be an issue for others.

I think the simplest solution would be to replace the line above with an
if block:

      if $DEBUG
        require 'pp'
        pp({ :inner_app => inner_app })
      end


Similar blocks appear in unicorn/bin/unicorn and
unicorn/bin/unicorn_rails. I am assuming the one in unicorn/bin/unicorn
is the one that allows it to work when using the -d flag. If there really
is never any reason to manually set $DEBUG I¹m sorry I wasted your time.

In any case, thank you for Unicorn!

Jim Robinson

------------------------------------------------------------------------------
CONFIDENTIALITY NOTICE: If you have received this email in error,
please immediately notify the sender by e-mail at the address shown. 
This email transmission may contain confidential information.  This
information is intended only for the use of the individual(s) or entity to
whom it is intended even if addressed incorrectly.  Please delete it from
your files if you are not the intended recipient.  Thank you for your
compliance.  Copyright (c) 2017 Cigna
==============================================================================


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using pp without require 'pp' when $DEBUG = True
  2017-11-16  0:57 using pp without require 'pp' when $DEBUG = True Robinson Jr, James P (Jim)      HHHH
@ 2017-11-16  1:30 ` Eric Wong
  2017-11-16 21:09   ` [PATCH] require 'pp' if $DEBUG is set by Rack app Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2017-11-16  1:30 UTC (permalink / raw)
  To: Robinson Jr, James P (Jim)      HHHH; +Cc: unicorn-public

"Robinson Jr, James P (Jim)      HHHH" <James.Robinson3@Cigna.com> wrote:
> This is not an issue if you run "unicorn -d config.ru², but If you
> manually set $DEBUG = true,  which I foolishly did because I didn¹t
> realize that $DEBUG was a special variable in ruby,  you get an undefined
> method error.   

Right, thanks for the bug report.

> I will be changing my code to use a different variable name, however I am
> not sure if there are valid reasons to manually set $DEBUG in ruby.  If
> there are, this may be an issue for others.

Yes, $DEBUG is a special variable in Ruby, and documented in the
ruby manpage; anybody is allowed to set it.

> I think the simplest solution would be to replace the line above with an
> if block:
> 
>       if $DEBUG
>         require 'pp'
>         pp({ :inner_app => inner_app })
>       end

Right, I'll prepare a patch tonight (gotta run out, soon) and
probably make a bugfix release in the next day or two, for this.

> Similar blocks appear in unicorn/bin/unicorn and
> unicorn/bin/unicorn_rails. I am assuming the one in unicorn/bin/unicorn
> is the one that allows it to work when using the -d flag. If there really
> is never any reason to manually set $DEBUG I¹m sorry I wasted your time.
> 
> In any case, thank you for Unicorn!

No problem!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] require 'pp' if $DEBUG is set by Rack app
  2017-11-16  1:30 ` Eric Wong
@ 2017-11-16 21:09   ` Eric Wong
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Wong @ 2017-11-16 21:09 UTC (permalink / raw)
  To: Robinson Jr, James P (Jim)      HHHH; +Cc: unicorn-public

While "unicorn -d" requires 'pp' when setting $DEBUG, we did not
account for (rare) Rack applications setting $DEBUG at load time.

Thanks-to: James P (Jim) Robinson Jr <James.Robinson3@Cigna.com>
---
 lib/unicorn.rb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 4bd7bda..e7bc9ce 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -59,7 +59,10 @@ def self.builder(ru, op)
         Object.const_get(File.basename(ru, '.rb').capitalize)
       end
 
-      pp({ :inner_app => inner_app }) if $DEBUG
+      if $DEBUG
+        require 'pp'
+        pp({ :inner_app => inner_app })
+      end
 
       return inner_app if no_default_middleware
 
-- 
EW

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-16  0:57 using pp without require 'pp' when $DEBUG = True Robinson Jr, James P (Jim)      HHHH
2017-11-16  1:30 ` Eric Wong
2017-11-16 21:09   ` [PATCH] require 'pp' if $DEBUG is set by Rack app Eric Wong

unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/unicorn-public
	git clone --mirror http://ou63pmih66umazou.onion/unicorn-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.unicorn
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.unicorn

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox