microsoft / microsoft/typespec
[Bug]: http-client-python - IndexError raised if there's an empty interface
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
### Describe the bug
If the main namespace has a empty interface, the python client generator breaks.
~~~
error @typespec/http-client-python/unknown-error: Can't generate Python client code from this TypeSpec. Please open an issue on https://github.com/microsoft/typespec'.
========================================= error stack start ================================================
Error: Command failed: /node_modules/@typespec/http-client-python/venv/bin/python /node_modules/@typespec/http-client-python/eng/scripts/setup/run_tsp.py --package-version=1.0.0b1 --generate-packaging-files=true --validate-versioning=true --package-name= --flavor=undefined --package-mode=azure-dataplane --from-typespec=true --models-mode=dpg --output-folder=/tsp-output/clients/python --tsp-file=/tmp/tsp-codegen/python-yaml-pathaee28f14-570c-4e78-8acf-cdad46280460.yaml
Traceback (most recent call last):
File "/node_modules/@typespec/http-client-python/eng/scripts/setup/run_tsp.py", line 40, in
codegen.CodeGenerator(output_folder=args.output_folder, tsp_file=args.tsp_file, **unknown_args).process()
File "/node_modules/@typespec/http-client-python/generator/pygen/codegen/__init__.py", line 84, in process
serializer.serialize()
File "/node_modules/@typespec/http-client-python/generator/pygen/codegen/serializers/__init__.py", line 122, in serialize
for client_namespace, client_namespace_type in self.code_model.client_namespace_types.items():
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/node_modules/@typespec/http-client-python/generator/pygen/codegen/models/code_model.py", line 187, in client_namespace_types
longest_namespace = sorted(self._client_namespace_types.keys())[-1]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range
at genericNodeError (node:internal/errors:983:15)
at wrappedFn (node:internal/errors:537:14)
at checkExecSyncError (node:child_process:892:11)
at execSync (node:child_process:964:15)
at onEmitMain (file:///node_modules/@typespec/http-client-python/dist/emitter/emitter.js:207:13)
at async Object.$onEmit [as emitFunction] (file:///node_modules/@typespec/http-client-python/dist/emitter/emitter.js:95:9)
at async runEmitter (file:///node_modules/@typespec/compiler/dist/src/core/program.js:711:9)
at async file:///node_modules/@typespec/compiler/dist/src/core/program.js:684:9
at async trackAction (file:///node_modules/@typespec/compiler/dist/src/core/logger/console-sink.js:133:24)
at async emit (file:///node_modules/@typespec/compiler/dist/src/core/program.js:682:12)
========================================= error stack end ================================================
Found 1 error.
~~~
### Reproduction
~~~typespec
import "@typespec/http";
@service(#{ title: "Employee Management" })
namespace EmployeeManagement {
interface EmployeeAPI {}
}
~~~
### Checklist
- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
Contributor guide
Assessment
This issue has not been assessed yet.