Skip to content

Commit

Permalink
Slight tweak to Ruby measure_manager: if POST body is nil, don't chok…
Browse files Browse the repository at this point in the history
…e on JSON.parse

No implicit conversion of nil into String isn't a good error message
  • Loading branch information
jmarrec committed Nov 14, 2024
1 parent b83b764 commit c4fb845
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ruby/engine/measure_manager_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def do_POST (request, response)

result = {}

data = JSON.parse(request.body, {:symbolize_names=>true})
data = JSON.parse(request.body || "{}", {:symbolize_names=>true})
my_measures_dir = data[:my_measures_dir]

if my_measures_dir
Expand All @@ -132,7 +132,7 @@ def do_POST (request, response)

result = []

data = JSON.parse(request.body, {:symbolize_names=>true})
data = JSON.parse(request.body || "{}", {:symbolize_names=>true})
uid = data[:uid]

if uid
Expand All @@ -156,8 +156,8 @@ def do_POST (request, response)

result = []

data = JSON.parse(request.body, {:symbolize_names=>true})
force_reload = false
data = JSON.parse(request.body || "{}", {:symbolize_names=>true})

# loop over all local BCL measures
OpenStudio::LocalBCL.instance.measures.each do |local_measure|
Expand All @@ -181,7 +181,7 @@ def do_POST (request, response)

result = []

data = JSON.parse(request.body, {:symbolize_names=>true})
data = JSON.parse(request.body || "{}", {:symbolize_names=>true})
measures_dir = data[:measures_dir] ? data[:measures_dir] : @my_measures_dir
force_reload = data[:force_reload] ? data[:force_reload] : false

Expand All @@ -205,7 +205,7 @@ def do_POST (request, response)

when "/compute_arguments"

data = JSON.parse(request.body, {:symbolize_names=>true})
data = JSON.parse(request.body || "{}", {:symbolize_names=>true})
measure_dir = data[:measure_dir ]
osm_path = data[:osm_path]
force_reload = data[:force_reload] ? data[:force_reload] : false
Expand Down Expand Up @@ -239,7 +239,7 @@ def do_POST (request, response)

when "/create_measure"

data = JSON.parse(request.body, {:symbolize_names=>true})
data = JSON.parse(request.body || "{}", {:symbolize_names=>true})
measure_dir = data[:measure_dir]

# name = data[:name] # we do not take name as input
Expand All @@ -263,7 +263,7 @@ def do_POST (request, response)

when "/duplicate_measure"

data = JSON.parse(request.body, {:symbolize_names=>true})
data = JSON.parse(request.body || "{}", {:symbolize_names=>true})
old_measure_dir = data[:old_measure_dir]
measure_dir = data[:measure_dir]

Expand Down

0 comments on commit c4fb845

Please sign in to comment.