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

-webide-representation doesn't work for arrays of primitive values #160

Open
matthewturk opened this issue Oct 24, 2023 · 3 comments
Open

Comments

@matthewturk
Copy link

I'm trying to use -webide-representation to display the values of a parameterized type. My guess is that it isn't supported, but I was kind of hoping there might be a way to make it work -- it's similar but not identical to the example using MACH-O on the website. My type definition is:

  fortran_record:
    params:
      - id: num_records
        type: u4
      - id: record_type
        type: str
    seq:
      - id: rec_size1
        type: u4
      - id: value
        type:
          switch-on: record_type
          cases:
            '"u4"': u4
            '"u8"': u8
            '"f4"': f4
            '"f8"': f8
        repeat: expr
        repeat-expr: num_records
      - id: rec_size2
        type: u4
    -webide-representation: "{value}"

When it parses, it throws this error:

Parse error (TypeError): Cannot read properties of undefined (reading 'ksyType')
Call stack: TypeError: Cannot read properties of undefined (reading 'ksyType')
    at ParsedTreeHandler.reprObject (https://ide.kaitai.io/js/v1/parsedToTree.js:81:35)
    at https://ide.kaitai.io/js/v1/parsedToTree.js:119:65
    at Array.map (<anonymous>)
    at https://ide.kaitai.io/js/v1/parsedToTree.js:119:48
    at [Symbol.replace] (<anonymous>)
    at String.replace (<anonymous>)
    at ParsedTreeHandler.reprObject (https://ide.kaitai.io/js/v1/parsedToTree.js:85:45)
    at ParsedTreeHandler.childItemToNode (https://ide.kaitai.io/js/v1/parsedToTree.js:145:33)
    at https://ide.kaitai.io/js/v1/parsedToTree.js:189:70
    at Array.map (<anonymous>)
    at ParsedTreeHandler.exportedToNodes (https://ide.kaitai.io/js/v1/parsedToTree.js:189:48)
    at https://ide.kaitai.io/js/v1/parsedToTree.js:267:34

My assumption is that the representation generation is being called before the type gets added as a property on the object by the switch statement, but perhaps that's wrong. I've tried a few different things, like using {value[0]} and whatnot, but it didn't quite work. Any ideas, or will this just require efforts along the same lines as kaitai-io/kaitai_struct#1073 ? Thanks!

@generalmimon
Copy link
Member

Turns out -webide-representation currently supports only user type arrays, not primitive type arrays. This works:

seq:
  - id: foo
    type: arr
types:
  arr:
    -webide-representation: '{items}'
    seq:
      - id: items
        type: item
        repeat: expr
        repeat-expr: 3
  item:
    -webide-representation: '{value:dec}'
    seq:
      - id: value
        type: s1

But once we replace type: item with type: s1, we get the error that you mentioned before:

seq:
  - id: foo
    type: arr
types:
  arr:
    -webide-representation: '{items}'
    seq:
      - id: items
        type: s1
        repeat: expr
        repeat-expr: 3
Parse error (TypeError): Cannot read properties of undefined (reading 'ksyType')

So if wrapping the item type to user-defined type is acceptable for you, it seems to work around the problem.

@generalmimon generalmimon changed the title -webide-representation of parameterized types -webide-representation doesn't work for arrays of primitive values Nov 12, 2023
@matthewturk
Copy link
Author

Thank you, this works for me! Happy to have the issue closed if appropriate.

@generalmimon
Copy link
Member

Happy to have the issue closed if appropriate.

Let's keep this issue open as a reminder that the problem exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants