You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
require"log"Log.setup level::trace
log =Log.for "testing"
log.error &.emit "test", does: {"this": :work?}
# symbol is not compatible ^^^^^^
Expected behavior
An error message at compilation about the symbol :work? being incompatible with Log::Metadata::Value
Actual behavior
An undesirably vague error message at compile time
In /usr/lib/crystal/log/metadata.cr:202:27
202 | def initialize(hash : NamedTuple | Hash)
^---------
Error: can't use NamedTuple(T) in unions yet, use a more specific type
with trace
In src/test.cr:8:5
8 | log.error &.emit "test", does: {"this": :work?}
^----
Error: instantiating 'Log#error()'
In src/test.cr:8:5
8 | log.error &.emit "test", does: {"this": :work?}
^----
Error: instantiating 'Log#error()'
In src/test.cr:8:13
8 | log.error &.emit "test", does: {"this": :work?}
^---
Error: instantiating 'Log::Emitter#emit(String)'
In /usr/lib/crystal/log/main.cr:194:7
194 | emit(message, kwargs)
^---
Error: instantiating 'emit(String, NamedTuple(does: NamedTuple(this: Symbol)))'
In /usr/lib/crystal/log/main.cr:198:55
198 | Entry.new(@source, @severity, message, Metadata.build(data), @exception)
^----
Error: instantiating 'Log::Metadata.class#build(NamedTuple(does: NamedTuple(this: Symbol)))'
In /usr/lib/crystal/log/metadata.cr:60:14
60 | Metadata.new(nil, value)
^--
Error: instantiating 'Log::Metadata.class#new(Nil, NamedTuple(does: NamedTuple(this: Symbol)))'
In /usr/lib/crystal/log/metadata.cr:36:10
36 | data.setup(parent, entries)
^----
Error: instantiating 'Log::Metadata#setup(Nil, NamedTuple(does: NamedTuple(this: Symbol)))'
In /usr/lib/crystal/log/metadata.cr:46:15
46 | entries.each_with_index do |key, value, i|
^--------------
Error: instantiating 'NamedTuple(does: NamedTuple(this: Symbol))#each_with_index()'
In /usr/lib/crystal/named_tuple.cr:567:5
567 | each do |key, value|
^---
Error: instantiating 'each()'
In /usr/lib/crystal/named_tuple.cr:567:5
567 | each do |key, value|
^---
Error: instantiating 'each()'
In /usr/lib/crystal/log/metadata.cr:46:15
46 | entries.each_with_index do |key, value, i|
^--------------
Error: instantiating 'NamedTuple(does: NamedTuple(this: Symbol))#each_with_index()'
In /usr/lib/crystal/log/metadata.cr:47:50
47 | ptr_entries[i] = {key: key, value: Value.to_metadata_value(value)}
^----------------
Error: instantiating 'Log::Metadata::Value.class#to_metadata_value(NamedTuple(this: Symbol))'
In /usr/lib/crystal/log/metadata.cr:216:42
216 | value.is_a?(Value) ? value : Value.new(value)
^--
Error: instantiating 'Log::Metadata::Value.class#new(NamedTuple(this: Symbol))'
In /usr/lib/crystal/log/metadata.cr:204:12
204 | hash.each do |key, value|
^---
Error: instantiating 'NamedTuple(this: Symbol)#each()'
In /usr/lib/crystal/log/metadata.cr:204:12
204 | hash.each do |key, value|
^---
Error: instantiating 'NamedTuple(this: Symbol)#each()'
In /usr/lib/crystal/log/metadata.cr:205:31
205 | raw[key.to_s] = Value.to_metadata_value(value)
^----------------
Error: instantiating 'Log::Metadata::Value.class#to_metadata_value(Symbol)'
In /usr/lib/crystal/log/metadata.cr:202:27
202 | def initialize(hash : NamedTuple | Hash)
^---------
Error: can't use NamedTuple(T) in unions yet, use a more specific type
As a suggestion, I would be totally fine with falling back to calling #inspect on types that aren't a member of logging metadata types to simply stringify them. This is usually what I do anyways when I want to throw some data into logs without wanting to go through structuring it into metadata.
Bug Report
Minimal example
playground
Expected behavior
An error message at compilation about the symbol
:work?
being incompatible withLog::Metadata::Value
Actual behavior
An undesirably vague error message at compile time
with trace
Other info
Crystal version
OS Version
The text was updated successfully, but these errors were encountered: