kaitai-io / kaitai_struct

Kaitai Struct: declarative language to generate binary data parsers in C++ / C# / Go / Java / JavaScript / Lua / Nim / Perl / PHP / Python / Ruby
https://kaitai.io
4.04k stars 199 forks source link

cryptic error message when confusing value and type #1024

Open milahu opened 1 year ago

milahu commented 1 year ago

as a noob, im tempted to confuse value and type

types:
  some_type:
    instances:
      # bad:
      # test.ksy: /:
      # error: Name(identifier(some_other_type)) (of class io.kaitai.struct.exprlang.Ast$expr$Name)
      some_instance_bad:
        value: 'some_other_type(some_index)'
      # good:
      some_instance:
        io: _root._io
        pos: some_index
        size: _root.header.page_size
        type: some_other_type(some_index)

error is not helpful

$ kaitai-struct-compiler -t python test.ksy
test.ksy: /:
        error: Name(identifier(some_other_type)) (of class io.kaitai.struct.exprlang.Ast$expr$Name)

because the yaml key path / is wrong, should be /types/some_type/instances/some_instance_bad/value because yaml position is missing, tracked in #229 because it should be more verbose, like error: not found: Name(identifier(some_other_type))

test.ksy ```yaml meta: id: test types: some_type: params: - id: some_index type: u4 seq: - id: some_bytes size: 10 instances: # bad: # test.ksy: /: # error: Name(identifier(some_other_type)) (of class io.kaitai.struct.exprlang.Ast$expr$Name) some_instance_bad: value: 'some_other_type(some_index)' # good: some_instance: io: _root._io pos: some_index size: _root.header.page_size type: some_other_type(some_index) some_other_type: params: - id: some_index type: u4 seq: - id: some_bytes size: 10 ```