Skip to content

Commit

Permalink
Merge pull request #158 from shybovycha/master
Browse files Browse the repository at this point in the history
Added python error catching
  • Loading branch information
gfx committed Dec 11, 2016
2 parents 8849bb1 + b2f7d70 commit d1c0721
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/pygments/popen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def mentos(method, args=[], kwargs={}, original_code=nil)
# mentos is now waiting for the header, and, potentially, code.
write_data(out_header, code)

check_for_error

# mentos will now return data to us. First it sends the header.
header = get_header

Expand All @@ -278,6 +280,25 @@ def mentos(method, args=[], kwargs={}, original_code=nil)
raise MentosError, "EPIPE"
end

def check_for_error
return if @err.closed?

timeout_time = 0.25 # set a very little timeout so that we do not hang the parser

Timeout::timeout(timeout_time) do
error_msg = @err.read

unless error_msg.empty?
@log.error "[#{Time.now.iso8601}] Error running python script: #{error_msg}"
stop "Error running python script: #{error_msg}"
raise MentosError, error_msg
end
end
rescue Timeout::Error
# during the specified time no error were found
@err.close
end


# Based on the header we receive, determine if we need
# to read more bytes, and read those bytes if necessary.
Expand Down

0 comments on commit d1c0721

Please sign in to comment.