Allan Odgaard mailinglist@textmate.org wrote:
On Mar 7, 2013, at 5:45 PM, Matt Neuburg matt@tidbits.com wrote:
Allan Odgaard wrote:
If it works, try this code as well:
rd, wr = IO.pipe fork do io = IO.for_fd(wr.to_i) io << "test\n" io.close end puts rd.gets
Did you run the above with Ruby 2.0?
Sure, and it outputs "test", but I really don't quite see what it has to with what I asked.
The problem I'm trying to solve is that any time there's an exception when running a Ruby script under TextMate, we wind up in RubyMate's catch_exception.rb, which starts like this:
at_exit do if (e = $!) && !e.instance_of?(SystemExit) require "#{ENV['TM_SUPPORT_PATH']}/lib/escape"
io = IO.for_fd(ENV['TM_ERROR_FD'].to_i)
io.write "<div id='exception_report' class='framed'>\n"
Etcetera. In Ruby 2.0 (but not in Ruby 1.8.7 or Ruby 1.9.3) we are failing on the "for_fd" line. The question is what to do about that.
If I substitute 2, as I said, I get output from the exception, sure, but it's displayed as unformatted raw HTML, which is not the same as what happens under 1.8.7 or 1.9.3. Moreover, under all versions of Ruby, TM_ERROR_FD is some high number such as 11, so the question remains why this is a valid parameter to "for_fd" under Ruby 1.8.7 and 1.9.3 but not Ruby 2.0.
Basically file descriptors are represented via integers, but the integer is just an index into a table of open files/pipes. So whether or not a given integer is a valid file descriptor depends on wether or not there is an entry in the process' table.
Yes, and the issue is why TM_ERROR_FD (which might be, say 11) is valid during catch_exception.rb's at_exit in Ruby 1.8.7 and 1.9.3 but not in Ruby 2.0. I was hoping you might have some idea about this. Could it be that the TM_ERROR_FD pipe created in executor.rb is somehow not surviving? Is it being closed too soon somehow? But why would that be the case in Ruby 2.0 only? Maybe that's the mystery that needs solving here... I'm not knowledgeable enough to experiment with executor.rb. m.