Permalink
Browse files

Added function for determining a trace which does not extend beyond t…

…he plotting script
  • Loading branch information...
1 parent 6e14d43 commit 3c7d3aadadceba1b5e99cbe826bd77b1258b7ee0 @mohawkjohn mohawkjohn committed Sep 19, 2011
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/sciruby/plotter.rb
@@ -46,7 +46,7 @@ def initialize script_or_handle
# Display new image.
img = image(:data => handle).tap { |i| i.move(11, 11) }
rescue => e
- alert "There appears to be an error in your plot code. Here's the trace:\n\n" + e.backtrace.join("\n"),
+ alert "There appears to be an error in your plot code. Here's the trace:\n\n" + Plotter.clean_trace(e.backtrace, script_or_handle).join("\n"),
:title => "Rubyvis Error - SciRuby"
end
end
@@ -55,6 +55,7 @@ def initialize script_or_handle
end
end
+
# A simple REPL without the P. Based roughly on IRB. Look on Wikipedia if you're not sure what a REPL is.
class Interpreter
def initialize filename, script = nil
@@ -88,6 +89,16 @@ def create_handle filename, script=nil
vis = Interpreter.new(filename, script).eval_script
RSVG::Handle.new_from_data(vis.to_svg).tap { |s| s.close }
end
+
+ # Clean a trace so only the relevant information is included.
+ def clean_trace bt, script_filename
+ short_trace = []
+ bt.each do |line|
+ break unless line.include?(script_filename)
+ short_trace << line
+ end
+ short_trace
+ end
end
end
end

0 comments on commit 3c7d3aa

Please sign in to comment.