← Back to issue list

fix: raise a clear error for non-UTF-8 project files

View original Github issue

Metadata

Project
craft-application
Number
#1125
Type
pull request
State
merged
Author
vismaytiwari
Labels
—
Created
Updated
Closed

Current evaluation

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.

Resolution: closed resolved

Reason: Merged into main as commit 043bc646 after @lengau merged main (#1126) for lint fixes and the author fixed an AttributeError on StringIO callers; all test CI jobs pass. The change converts uncaught UnicodeDecodeError into a friendly YamlError, closing issue #940.

Evaluated by: mr-cal-bot

No scores available.

Issue body

Fixes #940. `safe_yaml_load()` only caught `yaml.YAMLError`. Loading a project file encoded as UTF-16/UTF-32 makes PyYAML raise a builtin `UnicodeDecodeError` (a `ValueError`, not a `YAMLError`) while reading the stream, so it escaped uncaught and surfaced as a generic internal error. This catches `UnicodeDecodeError` and raises a friendly `YamlError` with a resolution pointing at the file encoding, consistent with the existing YAML error handling. A regression test with a UTF-32 project file is included. - [x] Have you followed the guidelines for contributing? - [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)? - [x] Have you successfully run `make lint && make test`? - [x] Have you added an entry to the changelog (`docs/reference/changelog.rst`)? --- ### Verification Ran locally against the changed files, all clean: - `ruff check` / `ruff format --check` - `ty` — no new diagnostics from this change - `codespell`, `prettier`, `shellcheck` - `vale` on the changelog entry — no alerts - `pytest tests/unit/util/test_yaml.py` — 18 passed, including a new `test_safe_yaml_loader_non_utf8` that fails with an uncaught `UnicodeDecodeError` without this fix and passes with it.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved 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.
stealth/space-bunny-alpha — closed resolved Merged PR #1125 (commit 043bc646) converts non-UTF-8 YAML decoding failures into a clear YamlError and adds a UTF-32 regression test.
qwen/qwen3.6-35b-a3b — — Merged fix for non-UTF-8 files. Catches unhandled UnicodeDecodeError in safe_yaml_load() and raises a clear YamlError with encoding guidance. Includes regression test, resolves CI failures by safely handling StringIO streams, and rebases changelog for v7.2.0.
qwen/qwen3.6-35b-a3b
Staleness: 5
Complexity: 15
Confidence: 95
needs review Catches UnicodeDecodeError in safe_yaml_load to provide a clear YamlError for non-UTF-8 files. Includes regression test. Approved by two reviewers, CI passing, and ready to merge.
qwen/qwen3.6-35b-a3b
Staleness: 5
Complexity: 15
Confidence: 90
needs review Fixes uncaught UnicodeDecodeError when loading non-UTF-8 YAML files by catching it and raising a descriptive YamlError. Includes regression test. Approved by two reviewers, CI passing, and ready for maintainer review.
qwen3.6-35b-a3b-mtp-q6
Staleness: 5
Complexity: 15
Confidence: 90
needs review Fixes uncaught UnicodeDecodeError when loading non-UTF-8 YAML project files by catching the exception and raising a descriptive YamlError. Includes regression test. Currently awaiting maintainer review.

Update history

Date Change
updated
updated

Related work

  • Related To: canonical/craft-application#940 (confidence 99%)

    Issue 'The app crashes when loading YAML files that are not UTF-8 encoded' — the bug this PR fixes; closed by it.

  • Related To: canonical/craft-application#1126 (confidence 88%)

    Maintainer PR merging main into the branch to bring in lint fixes; not the fix itself.

Related issues

Issue Project State Summary Similarity
#940 The app crashes when loading YAML files that are not UTF-8 encoded. craft-application closed 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.
78%