mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
clean yaml error message
This commit is contained in:
parent
5dea266895
commit
19c4c7d1e3
@ -161,9 +161,12 @@ def init(
|
|||||||
# =====
|
# =====
|
||||||
def _init_config(config_path: str, override_options: List[str], **load_flags: bool) -> Section:
|
def _init_config(config_path: str, override_options: List[str], **load_flags: bool) -> Section:
|
||||||
config_path = os.path.expanduser(config_path)
|
config_path = os.path.expanduser(config_path)
|
||||||
raw_config: Dict = load_yaml_file(config_path)
|
try:
|
||||||
|
raw_config: Dict = load_yaml_file(config_path)
|
||||||
|
except Exception as err:
|
||||||
|
raise SystemExit(f"ConfigError: Can't read config file {config_path!r}:\n{tools.efmt(err)}")
|
||||||
if not isinstance(raw_config, dict):
|
if not isinstance(raw_config, dict):
|
||||||
raise SystemExit(f"Config error: Top-level of the file {config_path!r} must be a dictionary")
|
raise SystemExit(f"ConfigError: Top-level of the file {config_path!r} must be a dictionary")
|
||||||
|
|
||||||
scheme = _get_config_scheme()
|
scheme = _get_config_scheme()
|
||||||
try:
|
try:
|
||||||
@ -177,7 +180,7 @@ def _init_config(config_path: str, override_options: List[str], **load_flags: bo
|
|||||||
|
|
||||||
return config
|
return config
|
||||||
except (ConfigError, UnknownPluginError) as err:
|
except (ConfigError, UnknownPluginError) as err:
|
||||||
raise SystemExit(f"Config error: {err}")
|
raise SystemExit(f"ConfigError: {err}")
|
||||||
|
|
||||||
|
|
||||||
def _patch_raw(raw_config: Dict) -> None:
|
def _patch_raw(raw_config: Dict) -> None:
|
||||||
|
|||||||
@ -28,15 +28,17 @@ from typing import Any
|
|||||||
import yaml
|
import yaml
|
||||||
import yaml.nodes
|
import yaml.nodes
|
||||||
|
|
||||||
|
from .. import tools
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
def load_yaml_file(path: str) -> Any:
|
def load_yaml_file(path: str) -> Any:
|
||||||
with open(path) as yaml_file:
|
with open(path) as yaml_file:
|
||||||
try:
|
try:
|
||||||
return yaml.load(yaml_file, _YamlLoader)
|
return yaml.load(yaml_file, _YamlLoader)
|
||||||
except Exception:
|
except Exception as err:
|
||||||
# Reraise internal exception as standard ValueError and show the incorrect file
|
# Reraise internal exception as standard ValueError and show the incorrect file
|
||||||
raise ValueError(f"Incorrect YAML syntax in file {path!r}")
|
raise ValueError(f"Invalid YAML in the file {path!r}:\n{tools.efmt(err)}") from None
|
||||||
|
|
||||||
|
|
||||||
class _YamlLoader(yaml.SafeLoader):
|
class _YamlLoader(yaml.SafeLoader):
|
||||||
|
|||||||
@ -158,7 +158,7 @@ def test_fail__not_htpasswd() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_fail__unknown_plugin() -> None:
|
def test_fail__unknown_plugin() -> None:
|
||||||
with pytest.raises(SystemExit, match="Config error: Unknown plugin 'auth/foobar'"):
|
with pytest.raises(SystemExit, match="ConfigError: Unknown plugin 'auth/foobar'"):
|
||||||
_run_htpasswd(["list"], "", internal_type="foobar")
|
_run_htpasswd(["list"], "", internal_type="foobar")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user