[PR #130] [MERGED] [config] Report a broken config instead of silently replacing it #134

Closed
opened 2026-10-13 19:47:47 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Glitchy-Sheep/boosty-downloader/pull/130
Author: @Glitchy-Sheep
Created: 8/9/2026
Status: ✅ Merged
Merged: 8/9/2026
Merged by: @Glitchy-Sheep

Base: main ← Head: fix/broken-config-not-overwritten


📝 Commits (1)

  • 459a460 fix: 🐛 A broken config is reported, not silently replaced

📊 Changes

6 files changed (+154 additions, -18 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 boosty_downloader/src/infrastructure/yaml_configuration/config.py (+65 -18)
📝 pyproject.toml (+1 -0)
➕ test/unit/configuration/__init__.py (+0 -0)
➕ test/unit/configuration/init_config_test.py (+85 -0)
📝 uv.lock (+2 -0)

📄 Description

Summary

A typo in config.yaml used to destroy the user's saved credentials: the app replaced the file with a blank sample and even reported it in green as a success. Now every config problem is explained in plain words and the file is never touched.

Problem

  • On any validation error the app called create_sample_config_file() over the user's file - auth_header and cookie were wiped without warning or backup
  • The message hid what was wrong and cheerfully said "Recreated it"
  • A YAML syntax error (the most common result of hand-editing) was not caught at all - the user got a raw traceback

Fix

  • The file stays untouched on every error path; the hint says: fix it by hand, or delete it for a fresh sample
  • Invalid values are listed per field: auth.cookie: should be text (wrap it in quotes), a mistyped key gets unknown setting - check the spelling
  • A syntax error points at the exact spot: the file breaks at line 3, column 17
  • Both translators (pydantic and the YAML parser) have a neutral fallback, so developer jargon never reaches the screen
  • pyyaml becomes a direct dependency: the code now imports it to catch YAMLError

Before / After

Before: one YAML typo - and the token is gone, replaced by an empty sample.
After: the app names the broken line or field, the file and the token survive.

Tests

  • test_broken_yaml_syntax_keeps_the_file / test_invalid_values_keep_the_file - the file stays byte-identical on both error paths
  • test_missing_config_creates_a_sample - the first-run path still works
  • test_pydantic_jargon_never_reaches_the_user / test_yaml_parser_jargon_never_reaches_the_user - translator fallbacks guard against leaking raw messages
  • Live CLI runs of all five scenarios (missing file, broken syntax, broken sections, mistyped key, garbage token) - each shows a short readable message and cmp confirms the file is untouched

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Glitchy-Sheep/boosty-downloader/pull/130 **Author:** [@Glitchy-Sheep](https://github.com/Glitchy-Sheep) **Created:** 8/9/2026 **Status:** ✅ Merged **Merged:** 8/9/2026 **Merged by:** [@Glitchy-Sheep](https://github.com/Glitchy-Sheep) **Base:** `main` ← **Head:** `fix/broken-config-not-overwritten` --- ### 📝 Commits (1) - [`459a460`](https://github.com/Glitchy-Sheep/boosty-downloader/commit/459a4604e037e1605616529a486b67d888c66c76) fix: :bug: A broken config is reported, not silently replaced ### 📊 Changes **6 files changed** (+154 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `boosty_downloader/src/infrastructure/yaml_configuration/config.py` (+65 -18) 📝 `pyproject.toml` (+1 -0) ➕ `test/unit/configuration/__init__.py` (+0 -0) ➕ `test/unit/configuration/init_config_test.py` (+85 -0) 📝 `uv.lock` (+2 -0) </details> ### 📄 Description ## Summary A typo in `config.yaml` used to destroy the user's saved credentials: the app replaced the file with a blank sample and even reported it in green as a success. Now every config problem is explained in plain words and the file is never touched. ## Problem - On any validation error the app called `create_sample_config_file()` over the user's file - `auth_header` and `cookie` were wiped without warning or backup - The message hid what was wrong and cheerfully said "Recreated it" - A YAML syntax error (the most common result of hand-editing) was not caught at all - the user got a raw traceback ## Fix - The file stays untouched on every error path; the hint says: fix it by hand, or delete it for a fresh sample - Invalid values are listed per field: `auth.cookie: should be text (wrap it in quotes)`, a mistyped key gets `unknown setting - check the spelling` - A syntax error points at the exact spot: `the file breaks at line 3, column 17` - Both translators (pydantic and the YAML parser) have a neutral fallback, so developer jargon never reaches the screen - `pyyaml` becomes a direct dependency: the code now imports it to catch `YAMLError` ## Before / After **Before:** one YAML typo - and the token is gone, replaced by an empty sample. **After:** the app names the broken line or field, the file and the token survive. ## Tests - `test_broken_yaml_syntax_keeps_the_file` / `test_invalid_values_keep_the_file` - the file stays byte-identical on both error paths - `test_missing_config_creates_a_sample` - the first-run path still works - `test_pydantic_jargon_never_reaches_the_user` / `test_yaml_parser_jargon_never_reaches_the_user` - translator fallbacks guard against leaking raw messages - Live CLI runs of all five scenarios (missing file, broken syntax, broken sections, mistyped key, garbage token) - each shows a short readable message and `cmp` confirms the file is untouched --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-13 19:47:47 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Glitchy-Sheep/boosty-downloader#134
No description provided.