rez icon indicating copy to clipboard operation
rez copied to clipboard

rez-pkg-cache --clean fails when it encounters malformed json

Open vanridal opened this issue 3 months ago • 1 comments

Situation: Local drive where cache dir is set ran out of space, this caused a package cache to write an empty a.json file to cached variant folder Now most rez-pkg-cache calls fail with:

>rez-pkg-cache --clean
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\opt\rez\bin\rez\rez-pkg-cache.exe\__main__.py", line 7, in <module>
  File "c:\opt\rez\3.2.1\Lib\site-packages\rez\cli\_entry_points.py", line 190, in run_rez_pkg_cache
    return run("pkg-cache")
           ^^^^^^^^^^^^^^^^
  File "c:\opt\rez\3.2.1\Lib\site-packages\rez\cli\_main.py", line 189, in run
    returncode = run_cmd()
                 ^^^^^^^^^
  File "c:\opt\rez\3.2.1\Lib\site-packages\rez\cli\_main.py", line 181, in run_cmd
    return func(opts, opts.parser, extra_arg_groups)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\opt\rez\3.2.1\Lib\site-packages\rez\cli\pkg-cache.py", line 167, in command
    pkgcache.clean()
  File "c:\opt\rez\3.2.1\Lib\site-packages\rez\package_cache.py", line 698, in clean
    for variant, rootpath, status in self.get_variants():
                                     ^^^^^^^^^^^^^^^^^^^
  File "c:\opt\rez\3.2.1\Lib\site-packages\rez\package_cache.py", line 586, in get_variants
    data = json.loads(f.read())
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\opt\python\py311\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\opt\python\py311\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\opt\python\py311\Lib\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)

Environment

  • OS Windows 10
  • Rez version 3.2.1
  • Rez python version 3.11

To reproduce rm contents of a.json file in a cached variant

Ideally it would be good if the malformed variant was ignored and seen as not cached, so the next occurrence of the variant being called to cache, will fix the issue

vanridal avatar Sep 18 '25 06:09 vanridal

Not that the error / stacktrace you highlighted shouldn't be fixed, but I think the similar problem and proposed solution over in https://github.com/AcademySoftwareFoundation/rez/issues/2014 would address the issue. Agree/disagree @vanridal ?

maxnbk avatar Sep 18 '25 20:09 maxnbk