Skip to content

Commit

Permalink
fix(driver): improve error messages around accessor usage
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Jul 19, 2023
1 parent 8d8fd5f commit 51d113d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: placeos-driver
version: 6.9.1
version: 6.9.2
crystal: ">= 1.0.0"

dependencies:
Expand Down
8 changes: 4 additions & 4 deletions src/placeos-driver/logger.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PlaceOS::Driver
PlaceOS::Driver.logger_io = log_io
backend = ::Log::IOBackend.new(log_io)
backend.formatter = LOG_FORMATTER
::Log.setup("*", ::Log::Severity::Info, backend)
::Log.setup("*", ::Log::Severity::Error, backend)

# :nodoc:
class_getter trace : Bool = false
Expand All @@ -19,7 +19,7 @@ class PlaceOS::Driver
def self.register_log_level_signal
Signal::USR1.trap do |signal|
@@trace = !@@trace
level = @@trace ? ::Log::Severity::Trace : ::Log::Severity::Info
level = @@trace ? ::Log::Severity::Trace : ::Log::Severity::Error
Log.info { "> Log level changed to #{level}" }

backend = ::Log::IOBackend.new(PlaceOS::Driver.logger_io)
Expand Down Expand Up @@ -66,14 +66,14 @@ class PlaceOS::Driver
# Don't worry it's not really an append, it's updating a hash with the
# backend as the key, so this is a clean update
@broadcast_backend.append(@protocol_backend, value ? ::Log::Severity::Debug : ::Log::Severity::None)
self.level = value ? ::Log::Severity::Debug : ::Log::Severity::Info
self.level = value ? ::Log::Severity::Debug : ::Log::Severity::Error
end

def initialize(
module_id : String,
logger_io : IO = ::PlaceOS::Driver.logger_io,
@protocol : Protocol = Protocol.instance,
severity : ::Log::Severity = ::Log::Severity::Info
severity : ::Log::Severity = ::Log::Severity::Error
)
@debugging = false

Expand Down
10 changes: 7 additions & 3 deletions src/placeos-driver/proxy/driver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ class PlaceOS::Driver::Proxy::Driver
function = @metadata.interface[function_name]?

# obtain the arguments provided
arguments = {{call.args}} {% if call.args.size == 0 %} of String {% end %}
{% if call.args.size == 0 %}
arguments = Tuple.new
{% else %}
arguments = {{call.args}}
{% end %}
{% if !call.named_args.is_a?(Nop) && call.named_args.size > 0 %}
named_args = {
{% for arg, index in call.named_args %}
{{arg.name.stringify.id}}: {{arg.value}},
{% end %}
}
{% else %}
named_args = {} of String => String
named_args = NamedTuple.new
{% end %}

# Execute is deferred so execution flow isn't interruped. }
Expand All @@ -85,7 +89,7 @@ class PlaceOS::Driver::Proxy::Driver
end

# provide a programatic way of calling a remote function similar to Ruby
def __send__(function_name : String | Symbol, arguments : Array | Tuple = [] of String, named_args : NamedTuple | Hash = {} of String => String)
def __send__(function_name : String | Symbol, arguments : Tuple = Tuple.new, named_args : NamedTuple = NamedTuple.new)
function_name = function_name.to_s
function = @metadata.interface[function_name]?
__exec_request__(function_name, function, arguments, named_args)
Expand Down
8 changes: 8 additions & 0 deletions src/placeos-driver/utilities/discovery.cr
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ abstract class PlaceOS::Driver
# Direct type: Int32, Display
# puts "{{name.var}} - {{ntype}} - {{optional}}"
{% ntype = ntype.stringify %}
{% if implementing %}
{% components = ntype.split("_") %}
{% if components[-1].to_i %}
{% components = components[0..-2] %}
{% end %}
{% ntype_fixed = components.join("_").id %}
{{ raise "unsupported use of 'implementing', you probably meant: accessor Array(#{ntype_fixed}), implementing: #{implementing}\nsee options: https://placeos.github.io/driver/PlaceOS/Driver.html#accessor(name,implementing=nil)-macro" }}
{% end %}
{% else %}
{% if ntype.name.stringify == "Array" %}
{% collection = true %}
Expand Down

0 comments on commit 51d113d

Please sign in to comment.