Attempt to parse YAML. Returns error message on failure, None on success.
(yaml_str: str)
| 188 | |
| 189 | @staticmethod |
| 190 | def _try_parse(yaml_str: str) -> Optional[str]: |
| 191 | """Attempt to parse YAML. Returns error message on failure, None on success.""" |
| 192 | try: |
| 193 | data = yaml.safe_load(yaml_str) |
| 194 | if not isinstance(data, dict): |
| 195 | return "YAML did not parse to a dictionary (got {})".format( |
| 196 | type(data).__name__ |
| 197 | ) |
| 198 | if "workflow" not in data: |
| 199 | return "Missing required top-level key: 'workflow'" |
| 200 | if "name" not in data: |
| 201 | return "Missing required top-level key: 'name'" |
| 202 | return None |
| 203 | except yaml.YAMLError as e: |
| 204 | return str(e) |