Skip to content

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

Open
@leha-bot

Description

@leha-bot

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)

Activity

self-assigned this
on Jan 22, 2024
memsharded

memsharded commented on Jan 22, 2024

@memsharded
Member

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?

leha-bot

leha-bot commented on Jan 22, 2024

@leha-bot
Author

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...

memsharded

memsharded commented on Jan 22, 2024

@memsharded
Member

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

memsharded commented on Jan 24, 2024

@memsharded
Member

Hi @leha-bot

Any feedback here? Thanks!

leha-bot

leha-bot commented on Feb 11, 2024

@leha-bot
Author

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)

memsharded

memsharded commented on Feb 11, 2024

@memsharded
Member

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

memsharded commented on Feb 13, 2024

@memsharded
Member

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!

transferred this issue fromconan-io/conanon Feb 13, 2024
added this to the 2 milestone on Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @leha-bot@memsharded

      Issue actions

        [bug] conan remote command fails if remotes.json doen't exist · Issue #3581 · conan-io/docs