From ea464b2e4932fae45087a672d0a080127789eab7 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Tue, 27 Sep 2022 08:23:07 -0700 Subject: [PATCH] chore: validate early Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- bentoml/_internal/configuration/containers.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bentoml/_internal/configuration/containers.py b/bentoml/_internal/configuration/containers.py index 9aa585f58dd..ba3746d66c1 100644 --- a/bentoml/_internal/configuration/containers.py +++ b/bentoml/_internal/configuration/containers.py @@ -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: @@ -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) @@ -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):