Fabric
Fabric copied to clipboard
Use ConfigParser to parse user config file
This fixes a bug caused by extra characters (e.g. newline) leading to an invalid ~/.config/fabric/.env file (according to the current parsing logic, that is). A newline should be allowed yet causes an exception to be raised with a traceback pointing elsewhere in the code. Such a traceback could be difficult to fix for some users and turn them away from fabric rather quickly. Plus, sometimes text editors will automatically add the newline.
Traceback (most recent call last):
File "/Users/ryan/fabric/client/fabric", line 68, in <module>
standalone.sendMessage(text)
File "/Users/ryan/fabric/client/utils.py", line 100, in sendMessage
print(response)
^^^^^^^^
UnboundLocalError: cannot access local variable 'response' where it is not associated with a value
Separately, I would also argue that the code around the traceback needs some changes too, but this change does fix the issue I first encountered.
A simpler change that would also fix the extra newline in the .env file would be to simply strip apikey. If that is preferred I can update this PR.
https://github.com/danielmiessler/fabric/blob/fba34371af239490ca81e43746542e1917ee65d8/client/utils.py#L16
apikey = f.read().split("=")[1].strip()
I didn't want to introduce any new dependencies (e.g. python-dotenv, pydantic-settings), preferred to use the standard library, hence configparser.
A simpler change that would also fix the extra newline in the
.envfile would be to simply stripapikey. If that is preferred I can update this PR.
Alternative PR at https://github.com/danielmiessler/fabric/pull/29
I think we fixed this by pulling the key in a different way. Thank you so much for this, though!