Spicy: Improve error messages reporting malformed unit names in EVT files.

This commit is contained in:
Robin Sommer 2024-11-08 12:56:02 +01:00
parent 2d935d9668
commit d57c125942
No known key found for this signature in database
GPG key ID: D8187293B3FFE5D0
5 changed files with 49 additions and 2 deletions

View file

@ -1165,7 +1165,7 @@ bool GlueCompiler::PopulateEvents() {
// to a unit now. // to a unit now.
ev.unit = ev.path.namespace_(); ev.unit = ev.path.namespace_();
if ( ! ev.unit ) { if ( ! ev.unit ) {
hilti::logger().error(hilti::util::fmt("unit type missing in hook '%s'", ev.path)); hilti::logger().error(hilti::util::fmt("namespace missing for '%s'", ev.path), ev.location);
return false; return false;
} }
@ -1174,7 +1174,7 @@ bool GlueCompiler::PopulateEvents() {
ev.hook = ev.path; ev.hook = ev.path;
} }
else { else {
hilti::logger().error(hilti::util::fmt("unknown unit type '%s'", ev.unit)); hilti::logger().error(hilti::util::fmt("no unit type of name '%s'", ev.path), ev.location);
return false; return false;
} }
} }

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[error] <...>/event-unit-type-fail.evt:5: no unit type of name 'TestAssertion::DoesNotExit'
[error] <Spicy support for Zeek>: aborting after errors

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[error] <...>/event-unit-type-fail.evt:5: no unit type of name 'TestAssertion::E'
[error] <Spicy support for Zeek>: aborting after errors

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[error] <...>/event-unit-type-fail.evt:12: namespace missing for 'Data'
[error] <Spicy support for Zeek>: aborting after errors

View file

@ -0,0 +1,38 @@
# @TEST-REQUIRES: have-spicy
#
# @TEST-EXEC-FAIL: spicyz -d -o test.hlto test.spicy %INPUT 2>output
# @TEST-EXEC: TEST_DIFF_CANONIFIER=diff-remove-abspath btest-diff output
#
# @TEST-DOC: Check that we catch various cases of invalid unit types in event definitions; regression test for #3988.
protocol analyzer spicy::Test over TCP:
parse with TestAssertion::Data;
on TestAssertion::Alias -> event Test::my_event(); # works
on Data -> event Test::my_event(); # failure: can't find unit due to missing namespace
@TEST-START-NEXT
protocol analyzer spicy::Test over TCP:
parse with TestAssertion::Data;
on TestAssertion::DoesNotExit -> event Test::my_event(); # failure: no such type
@TEST-START-NEXT
protocol analyzer spicy::Test over TCP:
parse with TestAssertion::Data;
on TestAssertion::E -> event Test::my_event(); # failure: exists, but not a unit type
@TEST-START-FILE test.spicy
module TestAssertion;
public type Data = unit {
: uint8;
};
public type Alias = Data;
public type E = enum { One };
@TEST-END-FILE