OceanSprint / tesh

TEstable SHell sessions in Markdown

Home Page:https://pypi.org/project/tesh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exitcodes parsing bug

zupo opened this issue · comments

The following snippet will crash tesh with the shown error:

```bash tesh-session="hello" tesh-ps1=">>>"
$ python
Python 3.10...
...

>>> exit()
```
Traceback (most recent call last):
  File "/nix/store/mvlayd2cp4lpgwfsmbdhva7ssa3h9vwn-python3.10-poetry2nix-env-scripts/bin/.tesh-wrapped", line 13, in <module>
    sys.exit(tesh())
  File "/nix/store/pwzxy20l2sqc9lh7abrdik6vbxpyrn6v-python3-3.10.4-env/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/nix/store/pwzxy20l2sqc9lh7abrdik6vbxpyrn6v-python3-3.10.4-env/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/nix/store/pwzxy20l2sqc9lh7abrdik6vbxpyrn6v-python3-3.10.4-env/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/nix/store/pwzxy20l2sqc9lh7abrdik6vbxpyrn6v-python3-3.10.4-env/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/zupo/work/tesh/src/tesh/__init__.py", line 59, in tesh
    test(filename, session, verbose, debug)
  File "/Users/zupo/work/tesh/src/tesh/test.py", line 94, in test
    exitcode = int(shell.before.decode("utf-8").strip())
ValueError: invalid literal for int() with base 10: 'File "<stdin>", line 1\r\n    echo $?\r\n         ^\r\nSyntaxError: invalid syntax'

The value of shell.before when it fails is:

'\r\n  File "<stdin>", line 1\r\n    echo $?\r\n         ^\r\nSyntaxError: invalid syntax\r\n'

It looks like Python doesn't exit here and tesh tries to get the exit codes by sending commands to python.