Skip to content

Commit

Permalink
fix: avoid crash on YAML files ruamel.yaml can not parse
Browse files Browse the repository at this point in the history
Fixes WEBLATE-19Q6
  • Loading branch information
nijel committed Nov 18, 2024
1 parent 53b3fd0 commit 0df129f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
----

* Not yet released.
* Fixed crasn on corrupt YAML files.

2.18
----
Expand Down
6 changes: 6 additions & 0 deletions translation_finder/discovery/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import json
import re
import warnings
from typing import TYPE_CHECKING

from ruamel.yaml import YAML
Expand Down Expand Up @@ -423,6 +424,11 @@ def adjust_format(self, result: ResultDict) -> None:
data = yaml.load(handle)
except (YAMLError, YAMLFutureWarning):
return
except Exception as error: # noqa: BLE001
# Weird errors can happen when parsing YAML, handle them gracefully, but
# emit a warning
warnings.warn(f"Could not parse YAML: {error}", stacklevel=0)
return
if isinstance(data, dict) and len(data) == 1:
key = next(iter(data.keys()))
if "filemask" in result:
Expand Down

0 comments on commit 0df129f

Please sign in to comment.