sinnwerkstatt/runrestic

TOML config file in XDG_CONFIG_HOME is being parsed as JSON

gruentee opened this issue · 8 comments

When trying to run runrestic 0.5.23 the follow error comes up:

$ runrestic
Traceback (most recent call last):
  File "/home/connzen/.local/bin/runrestic", line 8, in <module>
    sys.exit(runrestic())
  File "/home/connzen/.local/pipx/venvs/runrestic/lib/python3.8/site-packages/runrestic/runrestic/runrestic.py", line 65, in runrestic
    parsed_cfg = parse_configuration(c)
  File "/home/connzen/.local/pipx/venvs/runrestic/lib/python3.8/site-packages/runrestic/runrestic/configuration.py", line 131, in parse_configuration
    else json.load(file)
  File "/usr/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/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)

I suspect the if conditional in

if str(config_filename).endswith(".toml")

prevents the config file from being parsed as TOML. Sadly, neither .json nor .toml work because the config file's name in XDG_CONFIG_HOME is expected to have no suffix.

Hey @gruentee , thanks for filing this report.

I'm afraid I don't exactly understand. Where does your config file live exactly? ~/.config/restic/example.toml?

Hey @andreasnuesslein, thanks for making this useful wrapper around restic!

My config file lives at XDG_CONFIG_HOME/restic.

oh okay, yes well, I would expect a file extension :) could you just put it @ XDG_CONFIG_HOME/restic/gruentee.toml ?

or I think what actually should also work: XDG_CONFIG_HOME/restic.toml

Alright, I think I misinterpreted the error message:

FileNotFoundError: Error: No configuration files found in ['/etc/runrestic.toml', '/etc/runrestic.json', '/etc/runrestic', '/home/constantin/.config/runrestic']

I thought the file should live directly beneath XDG_CONFIG_HOME, but XDG_CONFIG_HOME/runrestic[.toml] doesn't work.
runrestic expects a directory XDG_CONFIG_HOME/runrestic/ with an arbitrarily named *{.toml,.json} file, I suppose?
Maybe the expected config paths should be suffixed with a slash in order to make it more obvious that a directory is expected.

XDG_CONFIG_HOME/restic.toml does not work.

 constantin@aspire-v772g  ~  touch .config/restic.toml   
 constantin@aspire-v772g  ~  runrestic               
Traceback (most recent call last):
  File "/usr/bin/runrestic", line 33, in <module>
    sys.exit(load_entry_point('runrestic==0.5.23', 'console_scripts', 'runrestic')())
  File "/usr/lib/python3.10/site-packages/runrestic/runrestic/runrestic.py", line 59, in runrestic
    raise FileNotFoundError(
FileNotFoundError: Error: No configuration files found in ['/etc/runrestic.toml', '/etc/runrestic.json', '/etc/runrestic', '/home/constantin/.config/runrestic']

Ah, yes I think you're right. Good call, thanks

It is a bit clearer here, actually:

https://github.com/sinnwerkstatt/runrestic#initializing-and-running

;)

Oh, it's already well documented but I missed it 🤦‍♂️
Time to close this issue, thanks for your help!