← Back to issue list

The app crashes when loading YAML files that are not UTF-8 encoded.

View original Github issue

Metadata

Project
craft-application
Number
#940
Type
issue
State
closed
Author
lengau
Labels
Status: Triaged Type: Bug
Created
Updated
Closed

Current evaluation

Fixed by merged PR #1125 (commit 043bc646): safe_yaml_load() now converts non-UTF-8 decode failures into a clear YamlError instead of a raw UnicodeDecodeError traceback; regression test added.

Resolution: closed resolved

Reason: Merged PR canonical/craft-application#1125 (commit 043bc646, "fix: raise a clear error for non-UTF-8 project files") added an `except UnicodeDecodeError` branch in craft_application/util/yaml.py::safe_yaml_load that raises errors.YamlError with "file is not valid UTF-8" and the resolution "Ensure <file> is encoded in UTF-8", plus a UTF-32 regression test.

Evaluated by: mr-cal-bot

No scores available.

Issue body

### Bug Description If you encode testcraft.yaml in utf-32, it gets: ``` UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte ``` We should handle that more nicely. ### To Reproduce ``` cp testcraft.yaml testcraft.yaml.bak iconv -f UTF-8 -t UTF-32 testcraft.yaml.bak > testcraft.yaml python -m testcraft pack ``` ### part yaml ```shell n/a ``` ### Relevant log output ```shell e 2025-10-15 14:49:39.953 Project file found at /home/lengau/Work/Code/craft-application/testcraft.yaml 2025-10-15 14:49:39.953 Loading project file '/home/lengau/Work/Code/craft-application/testcraft.yaml 2025-10-15 14:49:39.954 testcraft internal error: UnicodeDecodeError('utf-8', b'\xff\xfe\x00\x00n\x00\x00\x00a\x00\x00\x00m\x00\x00\x00e\x00\x00\x00:\x00\x00\x00 \x00\x00\x00c\x00\x00\x00r\x00\x00\x00a\x00\x00\x00f\x00\x00\x00t\x00\x00\x00-\x00\x00\x00a\x00\x00\x00p\x00\x00\x00p\x00\x00\x00l\x00\x00\x00i\x00\x00\x00c\x00\x00\x00a\x00\x00\x00t\x00\x00\x00i\x00\x00\x00o\x00\x00\x00n\x00\x00\x00\n\x00\x00\x00v\x00\x00\x00e\x00\x00\x00r\x00\x00\x00s\x00\x00\x00i\x00\x00\x00o\x00\x00\x00n\x00\x00\x00:\x00\x00\x00 \x00\x00\x00"\x00\x00\x000\x00\x00\x00.\x00\x00\x001\x00\x00\x00"\x00\x00\x00\n\x00\x00\x00\n\x00\x00\x00b\x00\x00\x00a\x00\x00\x00s\x00\x00\x00e\x00\x00\x00:\x00\x00\x00 \x00\x00\x00u\x00\x00\x00b\x00\x00\x00u\x00\x00\x00n\x00\x00\x00t\x00\x00\x00u\x00\x00\x00@\x00\x00\x002\x00\x00\x005\x00\x00\x00.\x00\x00\x001\x00\x00\x000\x00\x00\x00\n\x00\x00\x00p\x00\x00\x00l\x00\x00\x00a\x00\x00\x00t\x00\x00\x00f\x00\x00\x00o\x00\x00\x00r\x00\x00\x00m\x00\x00\x00s\x00\x00\x00:\x00\x00\x00\n\x00\x00\x00 \x00\x00\x00 \x00\x00\x00"\x00\x00\x00*\x00\x00\x00*\x00\x00\x00"\x00\x00\x00:\x00\x00\x00\n\x00\x00\x00 \x00\x00\x00 \x00\x00\x00 \x00\x00\x00 \x00\x00\x00b\x00\x00\x00u\x00\x00\x00i\x00\x00\x00l\x00\x00\x00d\x00\x00\x00-\x00\x00\x00o\x00\x00\x00n\x00\x00\x00:\x00\x00\x00 \x00\x00\x00[\x00\x00\x00a\x00\x00\x00m\x00\x00\x00d\x00\x00\x006\x00\x00\x004\x00\x00\x00,\x00\x00\x00 \x00\x00\x00a\x00\x00\x00r\x00\x00\x00m\x00\x00\x006\x00\x00\x004\x00\x00\x00,\x00\x00\x00 \x00\x00\x00p\x00\x00\x00p\x00\x00\x00c\x00\x00\x006\x00\x00\x004\x00\x00\x00e\x00\x00\x00l\x00\x00\x00,\x00\x00\x00 \x00\x00\x00s\x00\x00\x003\x00\x00\x009\x00\x00\x000\x00\x00\x00x\x00\x00\x00,\x00\x00\x00 \x00\x00\x00r\x00\x00\x00i\x00\x00\x00s\x00\x00\x00c\x00\x00\x00v\x00\x00\x006\x00\x00\x004\x00\x00\x00]\x00\x00\x00\n\x00\x00\x00 \x00\x00\x00 \x00\x00\x00 \x00\x00\x00 \x00\x00\x00b\x00\x00\x00u\x00\x00\x00i\x00\x00\x00l\x00\x00\x00d\x00\x00\x00-\x00\x00\x00f\x00\x00\x00o\x00\x00\x00r\x00\x00\x00:\x00\x00\x00 \x00\x00\x00[\x00\x00\x00a\x00\x00\x00l\x00\x00\x00l\x00\x00\x00]\x00\x00\x00\n\x00\x00\x00\n\x00\x00\x00p\x00\x00\x00a\x00\x00\x00r\x00\x00\x00t\x00\x00\x00s\x00\x00\x00:\x00\x00\x00\n\x00\x00\x00 \x00\x00\x00 \x00\x00\x00m\x00\x00\x00y\x00\x00\x00-\x00\x00\x00t\x00\x00\x00e\x00\x00\x00s\x00\x00\x00t\x00\x00\x00:\x00\x00\x00\n\x00\x00\x00 \x00\x00\x00 \x00\x00\x00 \x00\x00\x00 \x00\x00\x00p\x00\x00\x00l\x00\x00\x00u\x00\x00\x00g\x00\x00\x00i\x00\x00\x00n\x00\x00\x00:\x00\x00\x00 \x00\x00\x00n\x00\x00\x00i\x00\x00\x00l\x00\x00\x00\n\x00\x00\x00', 0, 1, 'invalid start byte') 2025-10-15 14:49:39.955 Traceback (most recent call last): 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/craft_application/application.py", line 669, in run 2025-10-15 14:49:39.955 return_code = self._run_inner() 2025-10-15 14:49:39.955 ^^^^^^^^^^^^^^^^^ 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/craft_application/application.py", line 636, in _run_inner 2025-10-15 14:49:39.955 project_service.configure(platform=platform, build_for=build_for) 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/craft_application/services/project.py", line 83, in configure 2025-10-15 14:49:39.955 platforms = self.get_platforms() 2025-10-15 14:49:39.955 ^^^^^^^^^^^^^^^^^^^^ 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/craft_application/services/project.py", line 274, in get_platforms 2025-10-15 14:49:39.955 raw_project = self.get_raw() 2025-10-15 14:49:39.955 ^^^^^^^^^^^^^^ 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/craft_application/services/project.py", line 201, in get_raw 2025-10-15 14:49:39.955 return copy.deepcopy(self._load_raw_project()) 2025-10-15 14:49:39.955 ^^^^^^^^^^^^^^^^^^^^^^^^ 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/craft_application/services/project.py", line 192, in _load_raw_project 2025-10-15 14:49:39.955 raw_yaml = util.safe_yaml_load(project_file) 2025-10-15 14:49:39.955 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/craft_application/util/yaml.py", line 110, in safe_yaml_load 2025-10-15 14:49:39.955 return yaml.load(stream, Loader=_SafeYamlLoader) # noqa: S506 2025-10-15 14:49:39.955 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/.venv/lib/python3.12/site-packages/yaml/__init__.py", line 79, in load 2025-10-15 14:49:39.955 loader = Loader(stream) 2025-10-15 14:49:39.955 ^^^^^^^^^^^^^^ 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/craft_application/util/yaml.py", line 94, in __init__ 2025-10-15 14:49:39.955 super().__init__(stream) 2025-10-15 14:49:39.955 File "/home/lengau/Work/Code/craft-application/.venv/lib/python3.12/site-packages/yaml/loader.py", line 34, in __init__ 2025-10-15 14:49:39.955 Reader.__init__(self, stream) 2025-10-15 14:49:39.956 File "/home/lengau/Work/Code/craft-application/.venv/lib/python3.12/site-packages/yaml/reader.py", line 85, in __init__ 2025-10-15 14:49:39.956 self.determine_encoding() 2025-10-15 14:49:39.956 File "/home/lengau/Work/Code/craft-application/.venv/lib/python3.12/site-packages/yaml/reader.py", line 124, in determine_encoding 2025-10-15 14:49:39.956 self.update_raw() 2025-10-15 14:49:39.956 File "/home/lengau/Work/Code/craft-application/.venv/lib/python3.12/site-packages/yaml/reader.py", line 178, in update_raw 2025-10-15 14:49:39.956 data = self.stream.read(size) 2025-10-15 14:49:39.956 ^^^^^^^^^^^^^^^^^^^^^^ 2025-10-15 14:49:39.956 File "<frozen codecs>", line 322, in decode 2025-10-15 14:49:39.956 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 2025-10-15 14:49:39.956 Full execution log: '/home/lengau/.local/state/testcraft/log/testcraft-20251015-144939.945779.log' ```

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Fixed by merged PR #1125 (commit 043bc646): safe_yaml_load() now converts non-UTF-8 decode failures into a clear YamlError instead of a raw UnicodeDecodeError traceback; regression test added.
stealth/space-bunny-alpha — closed resolved Fixed in merged PR #1125 (commit 043bc646): safe_yaml_load now converts UnicodeDecodeError into a clear UTF-8 error and includes a regression test.
qwen/qwen3.6-35b-a3b — — Fixed in PR #1125 by catching UnicodeDecodeError in safe_yaml_load and raising a standard YamlError with a clear resolution message. Includes a regression test for non-UTF-8 YAML files.
qwen/qwen3.6-35b-a3b
Staleness: 10
Complexity: 20
Confidence: 95
Support Request: 0
keep open App crashes with UnicodeDecodeError when loading non-UTF-8 YAML files. Triaged bug with an active fix PR (#1125) recently opened to catch the exception and provide a proper error message.
qwen3.6-35b-a3b-mtp-q6
Staleness: 5
Complexity: 15
Confidence: 90
Support Request: 0
keep open App crashes on non-UTF-8 YAML files due to unhandled UnicodeDecodeError. Issue is triaged and a fix is currently in progress via PR #1125.
qwen3.6-35b-a3b-mtp-q6
Staleness: 85
Complexity: 20
Confidence: 80
Support Request: 0
keep open App crashes with UnicodeDecodeError when loading non-UTF-8 YAML files. Triaged bug with no maintainer response or fix in over eight months.

Update history

Date Change
closed

Related work

  • Likely Fixed By: canonical/craft-application#1125 (confidence 99%)

    Merged PR that implements the fix; commit 043bc646 is the only recent change to craft_application/util/yaml.py.

  • Related To: canonical/craft-application#427 (confidence 40%)

    Earlier PR that wrapped YAML errors via errors.YamlError.from_yaml_error, the pattern the new UnicodeDecodeError handler follows.

Related issues

Issue Project State Summary Similarity
#1125 fix: raise a clear error for non-UTF-8 project files craft-application merged PR #1125 (vismaytiwari) merged as commit 043bc646: safe_yaml_load() now catches UnicodeDecodeError from UTF-16/32 project files and raises a clear YamlError; adds UTF-32 regression test and7.2.0 changelog entry. Fixes #940.
78%