Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(configuration): should validate config early #3041

Merged
merged 1 commit into from Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions bentoml/_internal/configuration/containers.py
Expand Up @@ -225,6 +225,14 @@ def __init__(
)
with open(default_config_file, "rb") as f:
self.config: t.Dict[str, t.Any] = yaml.safe_load(f)
if validate_schema:
try:
SCHEMA.validate(self.config)
except SchemaError as e:
raise BentoMLConfigException(
"Default configuration 'default_configuration.yml' does not"
" conform to the required schema."
) from e

# User override configuration
if override_config_file is not None:
Expand Down Expand Up @@ -285,7 +293,7 @@ def __init__(
override_config = unflatten(override_config_map)
except ValueError as e:
raise BentoMLConfigException(
f'Failed to parse config options from the env var: {e}. \n *** Note: You can use " to quote the key if it contains special characters. ***'
f"Failed to parse config options from the env var: {e}. \n *** Note: You can use '\"' to quote the key if it contains special characters. ***"
) from None
config_merger.merge(self.config, override_config)

Expand All @@ -297,8 +305,7 @@ def __init__(
SCHEMA.validate(self.config)
except SchemaError as e:
raise BentoMLConfigException(
"Default configuration 'default_configuration.yml' does not"
" conform to the required schema."
"Invalid configuration file was given."
) from e

def _finalize(self):
Expand Down