edc / bass

Make Bash utilities usable in Fish shell
MIT License
2.2k stars 70 forks source link

"Bass internal error!" when status code is not 0 #85

Closed livioribeiro closed 4 years ago

livioribeiro commented 4 years ago

I'm using Fedora 31 and just installed bass and I receive the following errors when running any command with that does not have a status code equal to "0":

Bass internal error!
Traceback (most recent call last):
  File "~/.config/fish/functions/__bass.py", line 112, in <module>
    script = gen_script()
  File "~/.config/fish/functions/__bass.py", line 72, in gen_script
    new_env = json.loads(new_env)
  File "/usr/lib64/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The problem is here: https://github.com/edc/bass/blob/c0d11420f35cfbcb62f94be0dfcf9baf70a9cea5/functions/__bass.py#L72

It seems that new_env is empty when the command does not return successfuly.

I changed that line to

new_env = json.loads(new_env) or old_env

and the error is gone, but I really do not know the consequences of doing that

lordlycastle commented 4 years ago

Have the same issue. Would love to know if this is a correct fix and get an update.

Actually that isn't working for me 😭

livioribeiro commented 4 years ago

I just found that the solution is to edit a few lines before that:

https://github.com/edc/bass/blob/c0d11420f35cfbcb62f94be0dfcf9baf70a9cea5/functions/__bass.py#L69

Changing that to:

new_env = new_env.strip() if new_env else old_env

But then again, I do not know the consequences of doing that.

edc commented 4 years ago

Just pushed a fix. Hope it helps.

fcwoknhenuxdfiyv commented 1 year ago

Sorry to revive an old issue, but this happens to me if I exit a script early with an exit 0 statement. Without the ability to exit early, scripts have to be written with a bunch of case or if/then code.

I looked at __bass.py and the code mentioned in the comments above is not there. Was the fix reverted?

fcwoknhenuxdfiyv commented 1 year ago

I overlooked the fact that the scripts are sourced, so I should be using return 0 instead.