add sanity check on config write as well as validation on read.
This commit is contained in:
parent
b567cb57e1
commit
d869d8e86f
@ -297,7 +297,10 @@ def write_section(self, section):
|
||||
try:
|
||||
mkdirp(self.path)
|
||||
with open(filename, 'w') as f:
|
||||
validate_section(data, section_schemas[section])
|
||||
syaml.dump(data, stream=f, default_flow_style=False)
|
||||
except jsonschema.ValidationError as e:
|
||||
raise ConfigSanityError(e, data)
|
||||
except (yaml.YAMLError, IOError) as e:
|
||||
raise ConfigFileError("Error writing to config file: '%s'" % str(e))
|
||||
|
||||
@ -533,3 +536,6 @@ def __init__(self, validation_error, data):
|
||||
|
||||
message = '%s: %s' % (location, validation_error.message)
|
||||
super(ConfigError, self).__init__(message)
|
||||
|
||||
class ConfigSanityError(ConfigFormatError):
|
||||
"""Same as ConfigFormatError, raised when config is written by Spack."""
|
||||
|
Loading…
Reference in New Issue
Block a user