Better error message when you try to MARK AS on coordinate (not possible)

pull/1200/head
Rick Carlino 2020-05-06 17:18:51 -05:00
parent 06d9dcb69d
commit 420c87601e
3 changed files with 21 additions and 19 deletions

View File

@ -3,7 +3,7 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
def update_resource(%AST{args: args, body: body}, env) do
quote do
unquote(__MODULE__).do_update(
unquote(__MODULE__).do_update_resource(
unquote(Map.fetch!(args, :resource)),
unquote(unpair(body, %{})),
unquote(env)
@ -11,22 +11,33 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
end
end
def do_update(%AST{kind: :identifier} = res, update, env) do
{name, environ, nil} = Compiler.compile_ast(res, env)
def do_update_resource(%AST{kind: :identifier} = variable, update, env) do
{name, environ, nil} = Compiler.compile_ast(variable, env)
value = Keyword.fetch!(environ, name)
%{resource_id: id, resource_type: kind} = value
FarmbotCeleryScript.SysCalls.update_resource(kind, id, update)
run_update_syscall(value, update)
end
def do_update(%AST{kind: :resource} = res, update, _) do
%{resource_id: id, resource_type: kind} = res.args
FarmbotCeleryScript.SysCalls.update_resource(kind, id, update)
def do_update_resource(%AST{kind: :resource} = res, update, _) do
run_update_syscall(res.args, update)
end
def do_update(res, _, _) do
def do_update_resource(res, _, _) do
raise "update_resource error. Please notfiy support: #{inspect(res)}"
end
defp run_update_syscall(%{resource_id: id, resource_type: kind}, update_params) do
FarmbotCeleryScript.SysCalls.update_resource(kind, id, update_params)
end
defp run_update_syscall(other, update) do
raise String.trim("""
MARK AS can only be used to mark resources like plants and devices.
It cannot be used on things like coordinates.
Ensure that your sequences and farm events us MARK AS on plants and not
coordinates. Tried updating #{inspect(other)} to #{inspect(update)}
""")
end
defp unpair([pair | rest], acc) do
IO.puts("TODO: Need to apply handlebars to `value`s.")
key = Map.fetch!(pair.args, :label)

View File

@ -44,16 +44,7 @@ defmodule FarmbotCore.FirmwareOpenTask do
firmware_path = Asset.fbos_config(:firmware_path)
firmware_hardware = Asset.fbos_config(:firmware_hardware)
if firmware_path && firmware_hardware do
IO.inspect(%{
firmware_path: firmware_path,
firmware_hardware: firmware_hardware,
}, label: "=== INIT FIRMWARE OPEN TASK (needs open)")
Config.update_config_value(:bool, "settings", "firmware_needs_open", true)
else
IO.inspect(%{
firmware_path: firmware_path,
firmware_hardware: firmware_hardware,
}, label: "=== INIT FIRMWARE OPEN TASK (does NOT need open)")
end
{:ok, %{timer: nil, attempts: 0, threshold: @attempt_threshold}}
end

View File

@ -29,7 +29,7 @@ defmodule FarmbotOS.SysCalls.ResourceUpdate do
def update_resource(kind, id, _params) do
{:error,
"""
Unknown resource: #{inspect({kind,id})}
Unknown resource: #{kind}.#{id}
"""}
end