Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ams-tschoening opened this issue Nov 30, 2020 · 0 comments · Fixed by #5 or #7

Comments

@ams-tschoening
Copy link
Contributor

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?

@ams-tschoening ams-tschoening changed the title "Kaitai::Struct::ValidationNotEqualError" throws strings instead of HEX-bytes like in Java. "Kaitai::Struct::ValidationNotEqualError" throws letters instead of HEX-bytes like in Java. Nov 30, 2020
ams-tschoening added a commit to ams-ts-kaitai-runtime/ruby that referenced this issue Dec 7, 2020
That's what's done in Java as well, though in Java individual bytes are separated by spaces as well. Am not doing so here to keep the implementation simple.

This fixes kaitai-io#4.
ams-tschoening added a commit to ams-ts-kaitai-runtime/ruby that referenced this issue Dec 7, 2020
That's what's done in Java as well, though in Java individual bytes are separated by spaces as well. Am not doing so here to keep the implementation simple.

This fixes kaitai-io#4.
generalmimon pushed a commit that referenced this issue Dec 15, 2020
* Output HEX-bytes instead of letters for ValidationNotEqualError.

That's what's done in Java as well, though in Java individual bytes are separated by spaces as well. Am not doing so here to keep the implementation simple.

This fixes #4.

* Added ValidationFailedError.strToHex like the corresponding
"byteArrayToHex" in Java, to have the same formatted output.

* HEX-conversion was already available and should be reused.
ams-tschoening added a commit to ams-ts-kaitai-runtime/ruby that referenced this issue Mar 3, 2021
…tai-io#5)

That's what's done in Java as well and HEX-conversion was already available anyway. Bracktes are added by purpose to keep output somewhat compatible with that of Java.

This fixes kaitai-io#4.
@generalmimon generalmimon reopened this Apr 20, 2021
generalmimon pushed a commit that referenced this issue Apr 20, 2021
…rays. (#7)

* Output HEX-bytes instead of letters for ValidationNotEqualError. (#5)

That's what's done in Java as well and HEX-conversion was already available anyway. Bracktes are added by purpose to keep output somewhat compatible with that of Java.

This fixes #4.

* Use an implementation supporting other objects than byte arrays as well.

#5 (comment)

* Don't handle human readable texts as byte arrays.

* Rephrased docs to make more clear what is meant.

* Changed phrases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants