Skip to content

Commit 440f4e6

Browse files
committed
fix(yaml): catch YAMLError
1 parent 29046f6 commit 440f4e6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/remarshal/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,9 @@ def _decode_yaml(input_data: bytes) -> Document:
447447
doc = yaml.load(input_data)
448448

449449
return cast(Document, doc)
450-
except (ruamel.yaml.scanner.ScannerError, ruamel.yaml.parser.ParserError) as e:
451-
msg = f"Cannot parse as YAML ({e})"
450+
except ruamel.yaml.YAMLError as e:
451+
problem = getattr(e, "problem", str(e))
452+
msg = f"Cannot parse as YAML ({problem})"
452453
raise ValueError(msg)
453454

454455

@@ -661,8 +662,9 @@ def _encode_yaml(data: Document, *, yaml_options: YAMLOptions) -> str:
661662
)
662663

663664
return out.getvalue()
664-
except ruamel.yaml.representer.RepresenterError as e:
665-
msg = f"Cannot convert data to YAML ({e})"
665+
except ruamel.yaml.YAMLError as e:
666+
problem = getattr(e, "problem", str(e))
667+
msg = f"Cannot convert data to YAML ({problem})"
666668
raise ValueError(msg)
667669

668670

0 commit comments

Comments
 (0)