Skip to content

Commit 028c141

Browse files
committed
refactor: change some compiler error messages
1 parent 3772489 commit 028c141

6 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/onyx-sql/bulk_query/where.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Onyx::SQL
77
raise "Onyx::SQL::Model::Options annotation must be defined for #{T}" unless options
88

99
pk = options[:primary_key]
10-
raise "Onyx::SQL::Model::Options annotation is missing :primary_key option for #{T}" unless pk
10+
raise "Onyx::SQL::Model::Options annotation is missing `primary_key` option for #{T}" unless pk
1111

1212
pk_ivar = T.instance_vars.find { |iv| "@#{iv.name}".id == pk.id }
1313
raise "Cannot find primary key field #{pk} for #{T}" unless pk_ivar

src/onyx-sql/model/instance_query_shortcuts.cr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ module Onyx::SQL::Model
2525
query.insert({{ivar.name}}: @{{ivar.name}}.not_nil!)
2626
end
2727
{% elsif ann && ann[:not_null] %}
28-
query.insert({{ivar.name}}: @{{ivar.name}}.not_nil!)
28+
if @{{ivar.name}}.nil?
29+
raise NilAssertionError.new("{{@type}}@{{ivar.name}} must not be nil on {{@type}}#insert")
30+
else
31+
query.insert({{ivar.name}}: @{{ivar.name}}.not_nil!)
32+
end
2933
{% else %}
3034
query.insert({{ivar.name}}: @{{ivar.name}})
3135
{% end %}

src/onyx-sql/query/insert.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module Onyx::SQL
3333
ivar = T.instance_vars.find(&.name.== key)
3434

3535
not_null = (a = ivar.annotation(Field) || ivar.annotation(Reference)) && a[:not_null]
36-
raise "On Query#insert: #{key} is nilable in compilation time (#{value}), but @#{ivar.name} has `not_null` option set to `true`. Consider calling `.not_nil!` on the value" if not_null && value.nilable?
36+
raise "On Query(#{T})#insert: #{key} is nilable in compilation time (`#{value}`), but #{T}@#{ivar.name} has `not_null` option set to `true`. Consider calling `.not_nil!` on the value" if not_null && value.nilable?
3737

3838
db_default = (a = ivar.annotation(Field)) && a[:default]
3939
is_pk = "@#{ivar.name}".id == T.annotation(Model::Options)[:primary_key].id

src/onyx-sql/query/join.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ module Onyx::SQL
174174
raise "Onyx::SQL::Model::Options annotation must be defined for #{type}" unless roptions
175175

176176
rtable = roptions[:table].id
177-
raise "Onyx::SQL::Model::Options annotation is missing :table option for #{type}" unless rtable
177+
raise "Onyx::SQL::Model::Options annotation is missing `table` option for #{type}" unless rtable
178178
%}
179179

180180
when .{{ivar.name}}?
181181
{% if key = ivar.annotation(Reference)[:key] %}
182182
{%
183183
rpk = roptions[:primary_key]
184-
raise "Onyx::SQL::Model::Options annotation is missing :primary_key option for #{type}" unless rpk
184+
raise "Onyx::SQL::Model::Options annotation is missing `primary_key` option for #{type}" unless rpk
185185

186186
rpk = rpk.name.stringify.split('@')[1].id
187187
on_op = (enumerable ? "IN".id : "=".id)
@@ -212,11 +212,11 @@ module Onyx::SQL
212212
type: type
213213
)
214214
{% else %}
215-
{% raise "Neither `key` nor `foreign_key` option is set for reference @#{ivar.name} in #{T}" %}
215+
{% raise "Neither `key` nor `foreign_key` option is set for reference @#{ivar.name} of #{T}" %}
216216
{% end %}
217217
{% end %}
218218
else
219-
raise "BUG: Cannot find reference #{reference} in #{T}::Reference"
219+
raise "BUG: Cannot find reference #{reference} in #{T}::Reference enum"
220220
end
221221
{% end %}
222222

src/onyx-sql/query/set.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module Onyx::SQL
5555
ivar = T.instance_vars.find(&.name.== key)
5656

5757
not_null = (a = ivar.annotation(Field) || ivar.annotation(Reference)) && a[:not_null]
58-
raise "On Query#set: #{key} is nilable in compilation time (#{value}), but @#{ivar.name} has `not_null` option set to `true`. Consider calling `.not_nil!` on the value" if not_null && value.nilable?
58+
raise "On Query(#{T})#set: #{key} is nilable in compilation time (`#{value}`), but #{T}@#{ivar.name} has `not_null` option set to `true`. Consider calling `.not_nil!` on the value" if not_null && value.nilable?
5959
%}
6060

6161
{% raise "Cannot find an instance variable named @#{key} in #{T}" unless ivar %}

src/onyx-sql/query/where.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module Onyx::SQL
5555

5656
{% raise "`primary_key: #{pk}` option didn't match any of `#{type}` instance variables" unless pk_rivar %}
5757

58-
{% raise "On Query#where: #{key} is nilable in compilation time (#{value}), but @#{ivar.name} has `not_null` option set to `true`. Consider calling `.not_nil!` on the value" if ann[:not_null] && value.nilable? %}
58+
{% raise "On Query(#{T})#where: #{key} is nilable in compilation time (`#{value}`), but #{T}@#{ivar.name} has `not_null` option set to `true`. Consider calling `.not_nil!` on the value" if ann[:not_null] && value.nilable? %}
5959

6060
{% reference_sql_key = ivar.annotation(Reference)[:key].id %}
6161

@@ -95,9 +95,9 @@ module Onyx::SQL
9595
{% elsif key.id == ivar.name %}
9696
{% not_null = (a = ivar.annotation(Field)) && a[:not_null] %}
9797

98-
{% raise "On Query#where: argument `#{key}:` is nilable in compilation time #{value}, but #{T}@#{ivar.name} has `not_null` option set to `true`. Consider calling `.not_nil!` on the `#{key}:` argument" if not_null && value.nilable? %}
98+
{% raise "On Query#where: argument `#{key}` is nilable in compilation time (`#{value}`), but #{T}@#{ivar.name} has `not_null` option set to `true`. Consider calling `.not_nil!` on the `#{key}` argument" if not_null && value.nilable? %}
9999

100-
{% raise "Invalid compile-time type `#{value}` for argument `#{key.symbolize}` in `Query(#{T})#where` call. Expected: `#{ivar.type}`" unless value <= ivar.type %}
100+
{% raise "Invalid compile-time type `#{value}` for argument `#{key.symbolize}` on `Query(#{T})#where` call. Expected: `#{ivar.type}`" unless value <= ivar.type %}
101101

102102
{% found = true %}
103103

0 commit comments

Comments
 (0)