kaitai-io / kaitai_struct_ruby_runtime

Kaitai Struct: runtime for Ruby

Home Page:https://rubygems.org/gems/kaitai-struct

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Kaitai::Struct::ValidationNotEqualError" throws letters instead of HEX-bytes like in Java.

ams-tschoening opened this issue · comments

The following YAML leads to the following Ruby, which leads to the error message underneath for some special input. While the error message in itself is correct and expected, it's textual content is simply different from that e.g. thrown in Java and in my opinion makes it more difficult to debug the concrete problem. I would therefore like to suggest changing the error message to provide a HEX-string instead of letters.

# par_oms_dll_command:
seq:
  - id:       check_value
    contents: [0x44]
    if:       not is_value_supported
def _read
  if !(is_value_supported)
    @check_value = @_io.read_bytes(1)
    raise Kaitai::Struct::ValidationNotEqualError.new([68].pack('C*'), check_value, _io, "/seq/0") if not check_value == [68].pack('C*')
  end

The error message in Ruby:

C:/Users/TSCHOE~1/AppData/Local/Temp/d20201130-11540-138pb9d/par_oms_dll_command.rb:56:in `_read': /seq/0: at pos 2: validation failed: not equal, expected "D", but got "G" (Kaitai::Struct::ValidationNotEqualError)

Bild_2020-11-30_173401

The error message in Java:

2020-11-27 14:51:12,855 ERROR
de.am_soft.sm_mtg.backend.svcs.ws.WsPackets.process: Processing a packet failed.
io.kaitai.struct.KaitaiStream$ValidationNotEqualError: /seq/0: at
pos 2: validation failed: not equal, expected [44], but got [47]

The important difference is that I get HEX-bytes in Java and a string in Ruby. I can easily change the implementation in Ruby to output a HEX-string as well:

super("not equal, expected #{expected.inspect}, but got #{actual.inspect}", io, src_path)

vs.

super("not equal, expected #{expected.unpack("H*")}, but got #{actual.unpack("H*")}", io, src_path)

C:/Users/TSCHOE~1/AppData/Local/Temp/d20201130-19396-139eoqo/par_oms_dll_command.rb:56:in `_read': /seq/0: at pos 2: validation failed: not equal, expected ["44"], but got ["47"] (Kaitai::Struct::ValidationNotEqualError)

Bild_2020-11-30_173926

What is the correct thing to do here?