kevinheavey / anchorpy

The Python Anchor client.
https://kevinheavey.github.io/anchorpy/
MIT License
222 stars 59 forks source link

client-gen fails when parsing empty type #74

Closed gallynaut closed 2 years ago

gallynaut commented 2 years ago

Switchboard uses defined types for all instruction parameters even if they are empty. This causes the client generation to fail when it encounters an empty type. Removing all empty types causes the generation to finish successfully.

IDL https://gist.github.com/gallynaut/60ea292c0f001274ac30bc8de6d3b33d

Example of an IDL entry that causes issues

  {
    "name": "AggregatorLockParams",
    "type": {
      "kind": "struct",
      "fields": []
    }
  },

Stack Trace

generating package...
generating program_id.py...
generating errors.py...
generating instructions...
generating types...
Traceback (most recent call last):
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/bin/anchorpy", line 8, in <module>
    sys.exit(app())
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/typer/main.py", line 500, in wrapper
    return callback(**use_params)  # type: ignore
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/anchorpy/cli.py", line 138, in client_gen
    gen_types(idl_obj, out)
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/anchorpy/clientgen/types.py", line 65, in gen_types
    gen_type_files(idl, types_dir)
  File "/Users/gally/Library/Caches/pypoetry/virtualenvs/switchboardpy-N0s6MIM5-py3.9/lib/python3.9/site-packages/anchorpy/clientgen/types.py", line 103, in gen_type_files
    formatted = format_str(code, mode=FileMode())
  File "src/black/__init__.py", line 1154, in format_str
  File "src/black/__init__.py", line 1164, in _format_str_once
  File "src/black/parsing.py", line 128, in lib2to3_parse
black.parsing.InvalidInput: Cannot parse: 9:0: @dataclass
kevinheavey commented 2 years ago

Will look into this. I'm guessing that on the client side, instantiating one of these types should look the same as instantiating a fieldless enum variant?