specs: List[Union[ServiceSpec, HostSpec]] = []
# YAML '---' document separator with no content generates
# None entries in the output. Let's skip them silently.
- content = [o for o in yaml_objs if o is not None]
+ try:
+ content = [o for o in yaml_objs if o is not None]
+ except yaml.scanner.ScannerError as e:
+ msg = f"Invalid YAML received : {str(e)}"
+ self.log.exception(msg)
+ return HandleCommandResult(-errno.EINVAL, stderr=msg)
+
for s in content:
- spec = json_to_generic_spec(s)
+ try:
+ spec = json_to_generic_spec(s)
+ except Exception as e:
+ if continue_on_error:
+ errs.append(f'Failed to convert {s} from json object: {str(e)}')
+ continue
+ else:
+ raise e
# validate the config (we need MgrModule for that)
if isinstance(spec, ServiceSpec) and spec.config: