rcmdnk / homebrew-file

Brewfile manager for Homebrew
http://homebrew-file.readthedocs.io/
MIT License
356 stars 29 forks source link

Python JSON Errors since the recent updates #155

Closed benburdick closed 1 year ago

benburdick commented 1 year ago

My brew-file is broken with the latest updates, throwing python errors:

raceback (most recent call last): File "/opt/homebrew/bin/brew-file", line 3549, in <module> sys.exit(main()) File "/opt/homebrew/bin/brew-file", line 3536, in main b.execute() File "/opt/homebrew/bin/brew-file", line 2857, in execute self.brew_cmd() File "/opt/homebrew/bin/brew-file", line 1627, in brew_cmd _ = self.initialize(check=False, debug_out=True) File "/opt/homebrew/bin/brew-file", line 2081, in initialize self.clean_list() File "/opt/homebrew/bin/brew-file", line 1939, in clean_list aliases = self.helper.get_formula_aliases() File "/opt/homebrew/bin/brew-file", line 368, in get_formula_aliases info = self.get_formula_info() File "/opt/homebrew/bin/brew-file", line 353, in get_formula_info info = list(json.loads("".join(lines))) File "/Users/ben/.pyenv/versions/3.10.10/lib/python3.10/json/__init__.py", line 346, in loads return _default_decoder.decode(s) File "/Users/ben/.pyenv/versions/3.10.10/lib/python3.10/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Users/ben/.pyenv/versions/3.10.10/lib/python3.10/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)

This occurs post package installation. I have tried this with the latest version of python 3.10 and 3.11 - whereas it was working with this versions prior to the recent updates

rcmdnk commented 1 year ago

Could you please run the following command and paste the results here?

brew --version
brew-file --version
echo $HOMEBREW_NO_GITHUB_API
ls -l $(brew --cache)/api
benburdick commented 1 year ago

Sure thing! Also wanted to mention that i have 2 identical M1 Macbooks (1 is a personal machine and the other is provided by my work) and I am experiencing this issue on them both.

` ❯ brew --version Homebrew 4.0.5 Homebrew/homebrew-core (git revision 7fd87f2ab8f; last commit 2023-02-18) Homebrew/homebrew-cask (git revision 1a8cad145c; last commit 2023-02-18) ❯ brew-file --version Homebrew 4.0.5 Homebrew/homebrew-core (git revision 7fd87f2ab8f; last commit 2023-02-18) Homebrew/homebrew-cask (git revision 1a8cad145c; last commit 2023-02-18) brew-file 9.0.5 04/Mar/2023 ❯ echo $HOMEBREW_NO_GITHUB_API

❯ ls -l $(brew --cache)/api Alias tip: ll $(brew --cache)/api .rw-r--r-- ben staff 4.8 MB Mon Mar 6 16:15:17 2023  cask.jws.json .rw-r--r-- ben staff 45 KB Mon Mar 6 16:15:19 2023  cask_names.before.txt .rw-r--r-- ben staff 45 KB Mon Mar 6 16:15:19 2023  cask_names.txt .rw-r--r-- ben staff 22 MB Mon Mar 6 16:15:17 2023  formula.jws.json .rw-r--r-- ben staff 5.2 KB Mon Mar 6 16:15:18 2023  formula_aliases.txt .rw-r--r-- ben staff 56 KB Mon Mar 6 16:15:19 2023  formula_names.before.txt .rw-r--r-- ben staff 56 KB Mon Mar 6 16:15:18 2023  formula_names.txt `

rcmdnk commented 1 year ago

Thanks!

It should be fixed at v9.0.6. Could you please try to upgrade brew-file and run commands?


Note:

It happens if homebrew-core or homebrew-casks are tapped and API is enabled (HOMEBREW_NO_GITHUB_API is not set)

If they are tapped, brew info --eval-all --json=v1 (or --json=v1) tries to update API information and shows like

$ command brew info --eval-all --json=v2
==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################## 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
######################################################################## 100.0% 
{

before stating json information.

brew-file tris to parse this output and raises an error like the above.

Updates happen if previous files are older than HOMEBREW_API_AUTO_UPDATE_SECS(450 sec by default).

If they are not tapped, no API update is executed (maybe a bug...?)

Anyway, outputs should be cleaned before parsing.

rcmdnk commented 1 year ago

If you do not intentionally remain taps of homebrew-core/homebrew-casks, it may be better to remove them by:

$ brew untap homebrew/homebrew-core homebrew/homebrew-casks

This will save your disk space and make several brew commands much faster. (especially brew info --eval-all, which is used by brew-file when Brewfile is initialised or updated.)

benburdick commented 1 year ago

Confirmed that 9.0.6 resolves the issue. Awesome! Thanks for the quick turnaround, hopefully that will prevent others from experiencing what I did :)