Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Syntax errors in homeserver.yaml lead to unclear errors #8738

Open
fw4hre0xxq opened this issue Nov 10, 2020 · 4 comments
Open

Syntax errors in homeserver.yaml lead to unclear errors #8738

fw4hre0xxq opened this issue Nov 10, 2020 · 4 comments
Labels
A-Config Configuration, or the documentation thereof T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. z-p3 (Deprecated Label)

Comments

@fw4hre0xxq
Copy link

Description:

Currently using the latest packages for ubuntu, having a malformed homeserver.yaml does not give a clear error message, instead causing a traceback, which exits 0, which then causes an automatic restart. This makes checking systemctl status in order to find out what went wrong very confusing. And then a check of journalctl gives something similar to the following

     File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
     "__main__", mod_spec)
     File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
     exec(code, run_globals)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/app/homeserver.py", line 512, in <modul
     main()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/app/homeserver.py", line 507, in main
     hs = setup(sys.argv[1:])
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/app/homeserver.py", line 342, in setup
     "Synapse Homeserver", config_options
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/config/_base.py", line 716, in load_or_
     config_dict = read_config_files(config_files)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/config/_base.py", line 762, in read_con
     yaml_config = yaml.safe_load(file_stream)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/__init__.py", line 162, in safe_load
     return load(stream, SafeLoader)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/__init__.py", line 114, in load
     return loader.get_single_data()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/constructor.py", line 49, in get_single_da
     node = self.get_single_node()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/composer.py", line 36, in get_single_node
     document = self.compose_document()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/composer.py", line 55, in compose_document
     node = self.compose_node(None, None)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/composer.py", line 84, in compose_node
     node = self.compose_mapping_node(anchor)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/composer.py", line 127, in compose_mapping
     while not self.check_event(MappingEndEvent):
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/parser.py", line 98, in check_event
     self.current_event = self.state()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/parser.py", line 439, in parse_block_mappi
     "expected <block end>, but found %r" % token.id, token.start_mark)
     yaml.parser.ParserError: while parsing a block mapping
     in "/etc/matrix-synapse/homeserver.yaml", line 35, column 1
     expected <block end>, but found '<block mapping start>'
     in "/etc/matrix-synapse/homeserver.yaml", line 727, column 3
     matrix-synapse.service: Control process exited, code=exited status=1
     matrix-synapse.service: Failed with result 'exit-code'.
     Failed to start Synapse Matrix homeserver.
     matrix-synapse.service: Service hold-off time over, scheduling restart.
     matrix-synapse.service: Scheduled restart job, restart counter is at 1.
     Stopped Synapse Matrix homeserver.
     Starting Synapse Matrix homeserver...
     Traceback (most recent call last):
     File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
     "__main__", mod_spec)
     File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
     exec(code, run_globals)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/app/homeserver.py", line 512, in <modul
     main()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/app/homeserver.py", line 507, in main
     hs = setup(sys.argv[1:])
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/app/homeserver.py", line 342, in setup
     "Synapse Homeserver", config_options
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/config/_base.py", line 716, in load_or_
     config_dict = read_config_files(config_files)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/synapse/config/_base.py", line 762, in read_con
     yaml_config = yaml.safe_load(file_stream)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/__init__.py", line 162, in safe_load
     return load(stream, SafeLoader)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/__init__.py", line 114, in load
     return loader.get_single_data()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/constructor.py", line 49, in get_single_da
     node = self.get_single_node()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/composer.py", line 36, in get_single_node
     document = self.compose_document()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/composer.py", line 55, in compose_document
     node = self.compose_node(None, None)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/composer.py", line 84, in compose_node
     node = self.compose_mapping_node(anchor)
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/composer.py", line 127, in compose_mapping
     while not self.check_event(MappingEndEvent):
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/parser.py", line 98, in check_event
     self.current_event = self.state()
     File "/opt/venvs/matrix-synapse/lib/python3.6/site-packages/yaml/parser.py", line 439, in parse_block_mappi
     "expected <block end>, but found %r" % token.id, token.start_mark)
     yaml.parser.ParserError: while parsing a block mapping
     in "/etc/matrix-synapse/homeserver.yaml", line 35, column 1
     expected <block end>, but found '<block mapping start>'
     in "/etc/matrix-synapse/homeserver.yaml", line 727, column 3```

A more clear error message I think would save people some headache.
@erikjohnston erikjohnston added the z-p3 (Deprecated Label) label Nov 10, 2020
@erikjohnston
Copy link
Member

Yeah, that is quite annoying. We should wrap calls to in a try/except and convert errors to ConfigError so that they're handled in the same fashion as other config errors (which should have better handling)

@richvdh
Copy link
Member

richvdh commented Nov 10, 2020

causing a traceback, which exits 0,

If this is true, it's #4640, but I notice your log (which seems to have lost some of its formatting) says:

matrix-synapse.service: Control process exited, code=exited status=1

... are you sure?

@richvdh richvdh changed the title parsing errors in homeserver.yaml file should not cause byzantine crashing Syntax errors in homeserver.yaml lead to unclear errors Jul 26, 2021
@richvdh
Copy link
Member

richvdh commented Jul 26, 2021

Nowadays, when I start synapse with a malformed homeserver.yaml, I get this:

rav@fred:~/work/synapse (rav/update_cachedcall_typing $%=)$ ./synctl.sh restart
Traceback (most recent call last):
  File "./synctl", line 350, in <module>
    main()
  File "./synctl", line 211, in main
    yaml_config = yaml.safe_load(file_stream)
  File "/home/rav/work/synapse/env3/lib/python3.8/site-packages/yaml/__init__.py", line 162, in safe_load
    return load(stream, SafeLoader)
  File "/home/rav/work/synapse/env3/lib/python3.8/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "/home/rav/work/synapse/env3/lib/python3.8/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "/home/rav/work/synapse/env3/lib/python3.8/site-packages/yaml/composer.py", line 39, in get_single_node
    if not self.check_event(StreamEndEvent):
  File "/home/rav/work/synapse/env3/lib/python3.8/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/home/rav/work/synapse/env3/lib/python3.8/site-packages/yaml/parser.py", line 171, in parse_document_start
    raise ParserError(None, None,
yaml.parser.ParserError: expected '<document start>', but found '<block mapping start>'
  in "homeserver.yaml", line 12, column 1

(with an exit code of 1). We could certainly improve this.

@erikjohnston erikjohnston added the T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. label Jul 26, 2021
@achambok
Copy link

Was this fixed? I'm getting the same errors in a venv as well on a CentOS 7

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Config Configuration, or the documentation thereof T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. z-p3 (Deprecated Label)
Projects
None yet
Development

No branches or pull requests

5 participants