Skip to content

Commit

Permalink
Include the file path in error messages when running external files
Browse files Browse the repository at this point in the history
Should hopefully fix sonic-pi-net#2336
  • Loading branch information
SunderB authored and cmaughan committed Jan 2, 2021
1 parent 19866e7 commit b02eb59
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/server/ruby/bin/sonic-pi-server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@

# read in init.rb if exists
if File.exists?(init_path)
sp.__spider_eval(File.read(init_path), silent: true)
sp.__spider_eval(File.read(init_path), path: init_path, silent: true)
else
begin
File.open(init_path, "w") do |f|
Expand Down
2 changes: 1 addition & 1 deletion app/server/ruby/lib/sonicpi/lang/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def with_swing(*args, &blk)
def run_file(path)
path = File.expand_path(path.to_s)
raise IOError, "Unable to run file - no file found with path: #{path}" unless File.exist?(path)
__spider_eval(File.read(path))
__spider_eval(File.read(path), path: path)
end
doc name: :run_file,
introduced: Version.new(2,11,0),
Expand Down
14 changes: 9 additions & 5 deletions app/server/ruby/lib/sonicpi/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,15 @@ def __spider_eval(code, info={})
if line
line = line.to_i

# TODO: Remove this hack when we have projects
w = info[:workspace]
w = normalise_buffer_name(w)
w = "buffer #{w}"
# TODO: end of hack
# If a filepath is given, use it; otherwise use the buffer name
w = ""
if (info[:path])
w = info[:path]
else
w = info[:workspace]
w = normalise_buffer_name(w)
w = "buffer #{w}"
end

err_msg = "[#{w}, line #{line}] \n #{message}"
error_line = code.lines.to_a[line - firstline] || ""
Expand Down

0 comments on commit b02eb59

Please sign in to comment.