Exceptions in Kaitaistruct code - Parse error: undefined

321 Views Asked by At

I am very new to Kaitai, please help me to solve these exceptions.

Code:

meta:
  id: picosat.ksy
  file-extension: picosat.ksy
  endian: be
  doc: |
  
    :field dest_callsign: ax25_frame.ax25_header.dest_callsign_raw.callsign_ror.callsign
    :field src_callsign: ax25_frame.ax25_header.src_callsign_raw.callsign_ror.callsign
    :field src_ssid: ax25_frame.ax25_header.src_ssid_raw.ssid
    :field dest_ssid: ax25_frame.ax25_header.dest_ssid_raw.ssid
    :field ctl: ax25_frame.ax25_header.ctl
    :field pid: ax25_frame.payload.pid
    :field epic_frame_Command_Token: ax25_frame.ax25_info.epic_frame.Command_Token
    :field epic_header_Source_SatelliteID: ax25_frame.ax25_info.epic_frame.epic_header.Source_SatelliteID
    :field epic_header_Session_ID: ax25_frame.ax25_info.epic_frame.epic_header.Session_ID
    :field epic_header_Destination_SatelliteID: ax25_frame.ax25_info.epic_frame.epic_header.Destination_SatelliteID
    :field epic_header_Source_MCUID: ax25_frame.ax25_info.epic_frame.epic_header.Source_MCUID
    :field epic_header_Desination_MCUID: ax25_frame.ax25_info.epic_frame.epic_header.Desination_MCUID
    :field epic_header_Command_Source: ax25_frame.ax25_info.epic_frame.epic_header.Command_Source
    :field epic_header_Command_Type: ax25_frame.ax25_info.epic_frame.epic_header.Command_Type
    :field epic_header_Get_AX25_state: ax25_frame.ax25_info.epic_frame.epic_header.Get_AX25_state
    :field epic_header_AX25_state: ax25_frame.ax25_info.epic_frame.epic_header.AX25_state
    :field epic_header_Command_Length: ax25_frame.ax25_info.epic_frame.epic_header.Command_Length
    :field epic_frame_Command_Payload: ax25_frame.ax25_info.epic_frame.epic_header.Command_Payload
    :field Command_Payload_Payload_Data: ax25_frame.ax25_info.Command_Payload.Payload_Data
    :field Command_Payload_TX_Buffer_AX25_Dec: ax25_frame.ax25_info.epic_frame.Command_Payload.TX_Buffer_AX25_Dec
    :field Command_Payload_TX_Buffer_AX25_HEX: ax25_frame.ax25_info.epic_frame.Command_Payload.TX_Buffer_AX25_HEX
    :field Command_Payload_TX_Buffer_EPIC_Dec: ax25_frame.ax25_info.epic_frame.Command_Payload.TX_Buffer_EPIC_Dec
    :field Command_Payload_TX_Buffer_EPIC_HEX: ax25_frame.ax25_info.epic_frame.Command_Payload.TX_Buffer_EPIC_HEX
    :field epic_frame_Cyclic_check: ax25_frame.ax25_info.epic_frame.Cyclic_check
    :field epic_frame_Command_Token: ax25_frame.ax25_info.epic_frame.Command_Token
    :field pyld_chksm: ax25_frame.ax25_info.pyld_chksm
  
  seq:
    - id: ax25_frame
      type: ax25_frame
  types:
    ax25_frame:
      seq:
        - id: ax25_header
          type: ax25_header
        - id: epic_frame
          type:
            switch-on: ax25_header.ctl & 0x13
            cases:
              0x03: ui_frame
              0x13: ui_frame
              0x00: i_frame
              0x02: i_frame
              0x10: i_frame
              0x12: i_frame
              # 0x11: s_frame
    ax25_header:
      seq:
        - id: dest_callsign_raw
          type: callsign_raw
        - id: dest_ssid_raw
          type: ssid_mask
        - id: src_callsign_raw
          type: callsign_raw
        - id: src_ssid_raw
          type: ssid_mask
        - id: ctl
          type: u1
    callsign_raw:
      seq:
        - id: callsign_ror
          process: ror(1)
          size: 6
          type: callsign
    callsign:
      seq:
        - id: callsign
          type: str
          encoding: ASCII
          size: 6
    ssid_mask:
      seq:
        - id: ssid_mask
          type: u1
      instances:
        ssid:
          value: (ssid_mask & 0x0f) >> 1
    ax25_info:
      seq:
        - id: epic_header
          type: epic_header
        - id: Command_Payload
          type: Command_Payload
        - id: Cyclic_check
          type: Cyclic_check
        - id: Command_Token
          type: Command_Token
    epic_header:
      seq:
        - id: Source_SatelliteID
          type: u1
          size: 0x06
        - id: Session_ID
          type: u1
          size: 0x06
        - id: Destination_SatelliteID
          type: u1
          size: 0x06
        - id: Source_MCUID
          type: u1
          size: 0x06
        - id: Destination_MCUID
          type: u1
          size: 0x06
        - id: Command_Source
          type: u1
          size: 0x01
        - id: Command_Type
          type: u1
          size: 0x07
        - id: Payload_Length
          type: u1
          size: 1
    Command_Type:
      seq:
        - id: Get_AX25_state
          type: u1
          doc: "get the state of AX25"
        - id: AX25_state
          type: u1
          size: 0x08
    Command_Payload:
      seq:
        - id: Payload_Data
          type: u1
        - id: TX_Buffer_AX25_Dec
          type: u1
        - id: TX_Buffer_AX25_HEX
          type: u4
        - id: TX_Buffer_epic_Dec
          type: u1
        - id: TX_Buffer_epic_HEX
          type: u4
        - id: pyld_chksm
          type: u4

Exceptions I got:

Parse error: undefined
Call stack: Error
    at $c_Lio_kaitai_struct_format_YAMLParseException.fillInStackTrace__jl_Throwable (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:24379:14)
    at $c_Lio_kaitai_struct_format_YAMLParseException.init___T__jl_Throwable__Z__Z (kaitai-struct-compiler.js:24485:10)
    at $c_Lio_kaitai_struct_format_YAMLParseException.init___T__sci_List (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:40914:58)
    at $c_Lio_kaitai_struct_format_ParseUtils$.ensureLegalKeys__sci_Map__sci_Set__sci_List__s_Option__V (/kaitai-struct-compiler.js:7832:66)
    at $c_Lio_kaitai_struct_format_MetaSpec$.fromYaml__O__sci_List__Lio_kaitai_struct_format_MetaSpec /kaitai-struct-compiler.js:28883:45)
    at $c_Lio_kaitai_struct_format_ClassSpec$.fromYaml__O__sci_List__Lio_kaitai_struct_format_MetaSpec__Lio_kaitai_struct_format_ClassSpec (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:28028:83)
    at $c_Lio_kaitai_struct_format_JavaScriptKSYParser$.yamlToSpecs__O__Lio_kaitai_struct_JavaScriptImporter__Lio_kaitai_struct_RuntimeConfig__s_concurrent_Future (kaitai-struct-compiler.js:7636:26)
    at $c_Lio_kaitai_struct_MainJs$.compile__T__sjs_js_Object__Lio_kaitai_struct_JavaScriptImporter__Z__sjs_js_Promise (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:3988:66)
    at $c_Lio_kaitai_struct_MainJs$.$$js$exported$meth$compile__T__sjs_js_Object__Lio_kaitai_struct_JavaScriptImporter__Z__O (kaitai-struct-compiler.js:3942:15)
    at $c_Lio_kaitai_struct_MainJs$.compile (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:4123:15)
    at CompilerService.compile (https://ide.kaitai.io/js/v1/KaitaiServices.js:85:82)
    at AppController.compile (https://ide.kaitai.io/js/v1/app.js:58:41)
    at AppController.recompile  io.kaitai.struct.format.YAMLParseException: /meta/doc: unknown key found, expected: application, bit-endian, encoding, endian, file-extension, id, imports, ks-debug, ks-opaque-types, ks-version, license, tags, title, xref
1

There are 1 best solutions below

4
On

Affiliate disclaimer: I'm a Kaitai Struct maintainer (see my GitHub profile).

First of all, please always put code snippets in fenced code blocks with the corresponding language identifier (for example lang-yaml for YAML language code, which is appropriate for .ksy specifications because the KSY language is based on YAML) - see Markdown help for more info. This is how it looks like:

```lang-yaml
meta:
  id: test
seq:
  # ...
```

If there is a code block where you don't want syntax highlighting to occur (like the parse error stack trace), use the lang-text label:

```lang-text
Parse error: undefined
Call stack: Error
    at $c_Lio_kaitai_struct_format_YAMLParseException.fillInStackTrace
    ...
```

Anyway, the problem with your code, which has the following structure:

meta:
  id: picosat # "picosat.ksy" is invalid, KS identifiers must satisfy /^[a-z][a-z0-9_]*$/
              #  -> it must start with a lowercase letter and optionally
              #     continue with alphanumeric characters and underscores
  file-extension: picosat
  endian: be
  doc: |
    ...
  
  seq:
    # ...
  types:
    # ...

is that you have doc, seq and types inside the /meta map as its subkeys. However, they are supposed to be on the same level as meta (i.e. no indent), so you need to decrease indent of these sections by one level (this can be done as Shift+Tab in many editors):

meta:
  id: picosat
  file-extension: picosat
  endian: be
# doc: |
#   ...
doc: |
  ...

# seq:
#   # ...
# types:
#   # ...
seq:
  # ...
types:
  # ...

You received the error /meta/doc: unknown key found because Kaitai Struct compiler doesn't recognize doc key under meta, and presents you a list of valid meta subkeys.

If you are in doubt what keys are supported in the .ksy and on what level, check out the KSY syntax diagram.