Skip to content

Commit

Permalink
fix: Handle ConfigurationError correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Jun 24, 2024
1 parent ac6b0a1 commit 5bce206
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/ai/backend/storage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ def status(
local_config = load_local_config(config_path, log_level, debug=debug)
except ConfigurationError as e:
print(
"ConfigurationError: Could not read or validate the storage-proxy local config:",
"ConfigurationError: Could not read or validate the storage-proxy local config.",
file=sys.stderr,
)
print(pformat(e.invalid_data), file=sys.stderr)
raise click.Abort()

pid_filepath = local_config["storage-proxy"]["pid-file"]

if not pid_filepath:
if not pid_filepath.is_file():
print(
'ConfigurationError: "pid-file" not found in the configuration file.',
file=sys.stderr,
Expand Down
17 changes: 3 additions & 14 deletions src/ai/backend/storage/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os
import sys
from pathlib import Path
from pprint import pformat
from typing import Any

import trafaret as t

from ai.backend.common import validators as tx
from ai.backend.common.config import (
ConfigurationError,
check,
etcd_config_iv,
override_key,
Expand Down Expand Up @@ -132,17 +129,9 @@ def load_local_config(
override_key(raw_cfg, ("logging", "level"), log_level)
override_key(raw_cfg, ("logging", "pkg-ns", "ai.backend"), log_level)

try:
local_config = check(raw_cfg, storage_proxy_local_config_iv)
local_config["_src"] = cfg_src_path
return local_config
except ConfigurationError as e:
print(
"ConfigurationError: Validation of storage-proxy local config has failed:",
file=sys.stderr,
)
print(pformat(e.invalid_data), file=sys.stderr)
raise
local_config = check(raw_cfg, storage_proxy_local_config_iv)
local_config["_src"] = cfg_src_path
return local_config


def load_shared_config(local_config: dict[str, Any]) -> AsyncEtcd:
Expand Down

0 comments on commit 5bce206

Please sign in to comment.