Improve yaml fault tolerance and handle check_config border cases (#3159)
This commit is contained in:
1 parent
267cda447e
commit
e8ad76c816
5 files changed
+90
-59
No files matched your search
@@ -221,14 +221,18 @@ def check(config_path):
|
||||
|
||||
try:
|
||||
bootstrap.from_config_file(config_path, skip_pip=True)
|
||||
res['secret_cache'] = yaml.__SECRET_CACHE
|
||||
return res
|
||||
res['secret_cache'] = dict(yaml.__SECRET_CACHE)
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
print(color('red', 'Fatal error while loading config:'), str(err))
|
||||
finally:
|
||||
# Stop all patches
|
||||
for pat in PATCHES.values():
|
||||
pat.stop()
|
||||
# Ensure !secrets point to the original function
|
||||
yaml.yaml.SafeLoader.add_constructor('!secret', yaml._secret_yaml)
|
||||
bootstrap.clear_secret_cache()
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def dump_dict(layer, indent_count=1, listi=False, **kwargs):
|
||||
|
||||
@@ -121,6 +121,16 @@ def _ordered_dict(loader: SafeLineLoader,
|
||||
line = getattr(node, '__line__', 'unknown')
|
||||
if line != 'unknown' and (min_line is None or line < min_line):
|
||||
min_line = line
|
||||
|
||||
try:
|
||||
hash(key)
|
||||
except TypeError:
|
||||
fname = getattr(loader.stream, 'name', '')
|
||||
raise yaml.MarkedYAMLError(
|
||||
context="invalid key: \"{}\"".format(key),
|
||||
context_mark=yaml.Mark(fname, 0, min_line, -1, None, None)
|
||||
)
|
||||
|
||||
if key in seen:
|
||||
fname = getattr(loader.stream, 'name', '')
|
||||
first_mark = yaml.Mark(fname, 0, seen[key], -1, None, None)
|
||||
|
||||
Reference in new issue
Block a user