Skip to content

Commit

Permalink
Revert "Merge pull request sonic-pi-net#2470 from SunderB/patch/show-…
Browse files Browse the repository at this point in the history
…filepaths-in-errors"

This reverts commit fca92c0, reversing
changes made to a64755b.
  • Loading branch information
samaaron committed Oct 3, 2020
1 parent 2cecdd4 commit 64bafc7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 40 deletions.
6 changes: 3 additions & 3 deletions 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), type: :file, name: init_path, silent: true)
sp.__spider_eval(File.read(init_path), silent: true)
else
begin
File.open(init_path, "w") do |f|
Expand Down Expand Up @@ -321,7 +321,7 @@
server.add_method("/run-code") do |args|
gui_id = args[0]
code = args[1].force_encoding("utf-8")
sp.__spider_eval(code, type: :eval, name: "osc-/run-code")
sp.__spider_eval code
end

server.add_method("/save-and-run-buffer") do |args|
Expand All @@ -330,7 +330,7 @@
code = args[2].force_encoding("utf-8")
workspace = args[3]
sp.__save_buffer(buffer_id, code)
sp.__spider_eval(code, type: :workspace, name: workspace)
sp.__spider_eval code, {workspace: workspace}
end

server.add_method("/save-buffer") do |args|
Expand Down
7 changes: 2 additions & 5 deletions 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), type: :file, name: path)
__spider_eval(File.read(path))
end
doc name: :run_file,
introduced: Version.new(2,11,0),
Expand All @@ -477,7 +477,7 @@ def run_file(path)
run_file \"~/path/to/sonic-pi-code.rb\" #=> will run the contents of this file"]

def run_code(code)
__spider_eval(code.to_s, type: :eval, name: "run_code")
__spider_eval(code.to_s)
end
doc name: :run_code,
introduced: Version.new(2,11,0),
Expand Down Expand Up @@ -4745,9 +4745,6 @@ def assert_similar(a, b, msg=nil)
def load_buffer(path)
path = File.expand_path(path.to_s)
raise IOError, "Unable to load buffer - no file found with path: #{path}" unless File.exist?(path)

raise RuntimeError, "Unable to retrieve the current workspace. Current job info: #{__current_job_info}" unless __current_job_info[:workspace]

buf = __current_job_info[:workspace]
__info "loading #{buf} with #{path}"
__replace_buffer(buf, File.read(path))
Expand Down
50 changes: 18 additions & 32 deletions app/server/ruby/lib/sonicpi/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module RuntimeMethods
def load_snippets(path=snippets_path, quiet=false)
path = File.expand_path(path)
Dir["#{path}/**/*.sps"].each do |p|

lines = File.readlines(p)
key = nil
completion = ""
Expand Down Expand Up @@ -313,8 +314,14 @@ def __error(e, m=nil)
info = __current_job_info
err_msg.gsub(/for #<SonicPiSpiderUser[a-z0-9:]+>/, '')
res = ""
w = info[:display_name]
w = info[:workspace]
if line != -1

# TODO: Remove this hack when we have projects
w = normalise_buffer_name(w)
w = "buffer " + w
# TODO: end of hack

res = res + "[#{w}, line #{line}]"
else
res = res + "[#{w}]"
Expand Down Expand Up @@ -784,12 +791,10 @@ def __spider_eval(code, info={})
firstline = 1
firstline -= code.lines.to_a.take_while{|l| l.include? "#__nosave__"}.count
start_t_prom = Promise.new

display_name = get_spider_eval_display_name(info[:type], info[:name])
info[:workspace] = 'eval' unless info[:workspace]

info[:name].freeze
info[:workspace].freeze
info.freeze
display_name.freeze

job_in_thread = nil
job = Thread.new do
Expand Down Expand Up @@ -821,7 +826,7 @@ def __spider_eval(code, info={})
code = PreParser.preparse(code, SonicPi::Lang::Core.vec_fns)

job_in_thread = in_thread seed: 0 do
eval(code, nil, info[:name], firstline)
eval(code, nil, info[:workspace], firstline)
end
__schedule_delayed_blocks_and_messages!
rescue Stop => e
Expand All @@ -835,7 +840,13 @@ def __spider_eval(code, info={})
if line
line = line.to_i

err_msg = "[#{display_name}, line #{line}] \n #{message}"
# TODO: Remove this hack when we have projects
w = info[:workspace]
w = normalise_buffer_name(w)
w = "buffer #{w}"
# TODO: end of hack

err_msg = "[#{w}, line #{line}] \n #{message}"
error_line = code.lines.to_a[line - firstline] || ""
else
line = -1
Expand Down Expand Up @@ -1262,31 +1273,6 @@ def beautify_ruby_source(source)
res = res.gsub(') ___SONIC_PI_RND_TMP_PLACEHOLDER___ /', ')/')
res = res.gsub('] ___SONIC_PI_SQR_TMP_PLACEHOLDER___ /', ']/')
end

def get_spider_eval_display_name(type, name)
case info[:type]
when :workspace
"buffer #{normalise_buffer_name(name)}"
when :file
name
when :eval
normalise_eval_name(name)
end
end

def normalise_eval_name(name)
if (name.nil?)
return "unnamed eval"
end

norm = case name
when "osc-/run-code"
"eval"
else
name
end
return norm
end

def normalise_buffer_name(name)
norm = case name
Expand Down

0 comments on commit 64bafc7

Please sign in to comment.