docs icon indicating copy to clipboard operation
docs copied to clipboard

[bug] conan remote command fails if remotes.json doen't exist

Open leha-bot opened this issue 7 months ago • 7 comments

Environment details

  • Operating System+version: Windows 10
  • Compiler+version: N/A
  • Conan version: 2.0.16
  • Python version: 3.10.6

Steps to reproduce

  1. Accidentally remove remotes.json from ~/remotes.json
  2. Try to re-add conancenter
  3. Got an exception

Logs

$ conan remote add conancenter https://center.conan.io                                                                                    
ERROR: Traceback (most recent call last):                                                                                                                            
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conan\cli\cli.py", line 270, in main                                                  cli.run(args)                                                                                                                                                    
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conan\cli\cli.py", line 180, in run                                                   command.run(self._conan_api, args[0][1:])                                                                                                                       
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conan\cli\command.py", line 142, in run                                               sub.run(conan_api, parser, *args)                                                                                                                                
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conan\cli\command.py", line 156, in run                                               info = self._method(conan_api, parent_parser, self._parser, *args)                                                                                               
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conan\cli\commands\remote.py", line 78, in remote_add                                 conan_api.remotes.add(r, force=args.force, index=args.index)                                                                                                     
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conan\api\subapi\remotes.py", line 66, in add                                         return RemoteRegistry(self._remotes_file).add(remote, force=force, index=index)                                                                                  
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conans\client\cache\remote_registry.py", line 163, in add                             remotes = self._load_remotes()                                                                                                                                   
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conans\client\cache\remote_registry.py", line 151, in _load_remotes                   return _Remotes.load(self._filename)                                                                                                                             
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\site-packages\conans\client\cache\remote_registry.py", line 33, in load                             data = json.loads(text)                                                                                                                                          
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 346, in loads                                                               return _default_decoder.decode(s)                                                                                                                                
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode                                                               obj, end = self.raw_decode(s, idx=_w(s, 0).end())                                                                                                                
File "C:\Users\AlexF\AppData\Local\Programs\Python\Python310\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)                                                                                                                                                                                                                                                               
ERROR: Expecting value: line 1 column 1 (char 0)

leha-bot avatar Jan 22 '24 13:01 leha-bot

Hi @leha-bot

Thanks for your report. It seems there is something different there, I can't reproduce:

rm ..\..\.conan2\remotes.json && conan remote add local http://url.com && conan remote list
conancenter: https://center.conan.io [Verify SSL: True, Enabled: True]
local: http://url.com [Verify SSL: True, Enabled: True

works fine. Can you please try the above commands?

memsharded avatar Jan 22 '24 14:01 memsharded

Oh, it seems that the simple deletion is not sufficient to reproduce, I had had some another remotes (excluding conancenter) in that remotes.json, and conancenter was explicitly excluded (for test purposes on internal infra), seems this is a important detail for this, would try to reproduce it again...

leha-bot avatar Jan 22 '24 21:01 leha-bot

I am afraid I can't reproduce with that info either. Trying to add, remove, etc, doesn't make it fail like that.

I think the key is here: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

This only happens if the json file is corrupted and not valid json. Maybe your remotes.json was broken? Someone accidentally touched it? If not, can you please try to provide steps to reproduce the error? Thanks!

memsharded avatar Jan 22 '24 22:01 memsharded

Hi @leha-bot

Any feedback here? Thanks!

memsharded avatar Jan 24 '24 11:01 memsharded

hello, sorry for late responce. It seems that the weird symbol was from PowerShell 'New-Item' (but I'm not sure). From my friends I heard that Powershell sometimes likes to add the Unicode BOM symbol in generated files (e.g., after pipelining like someprog > my.txt)

I think that if you have any resources, then it would be good to add the 'fool check' for weird BOM/file size (I saw some similar in YouCompleteMe Vim plugin for LSP: https://github.com/ycm-core/ycmd/pull/1680/files)

leha-bot avatar Feb 11 '24 15:02 leha-bot

hello, sorry for late responce.

No prob, thanks for following up :)

It seems that the weird symbol was from PowerShell 'New-Item' (but I'm not sure). From my friends I heard that Powershell sometimes likes to add the Unicode BOM symbol in generated files (e.g., after pipelining like someprog > my.txt)

I see. In general this fie is managed with the conan remote command, it makes sense now the behavior if powershell is adding extra characters unexpected. I also think that not only the characters, but also the encoding might be different.

I think that if you have any resources, then it would be good to add the 'fool check' for weird BOM/file size (I saw some similar in YouCompleteMe Vim plugin for LSP: https://github.com/ycm-core/ycmd/pull/1680/files)

Seems a bit overkill at the moment, the check adds some complexity and cost too, I'll check with the team for more opinions.

memsharded avatar Feb 11 '24 21:02 memsharded

I have discussed with the team, and yes, it seems a bit overkill at the moment I am moving this to the docs, to clarify all files are utf-8 without bom headers. Thanks for the feedback!

memsharded avatar Feb 13 '24 13:02 memsharded