Skip to content

Commit

Permalink
fix(configuration): should validate config early (#3041)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnphm committed Sep 27, 2022
1 parent 7bf352b commit d189df7
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit d189df7

Please sign in to comment.