Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

python-validation-errors

/python-validation-errors

Dodaje do skryptów Python ścisłą walidację wejścia i czytelne komunikaty o błędach z kodami wyjścia i testami.

Licencja
MIT
Ostatnia zmiana repozytorium
11.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 11.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Dodaje do skryptów Python ścisłą walidację wejścia i czytelne komunikaty o błędach z kodami wyjścia i testami.

Oryginalny opis (EN)

Implement strict input validation and error/log messages in Python: ERROR/WARNING/INFO prefixes on stderr, exit codes, messages that name file, record, expected, observed and fix, collect-then-report validators, an error class with run_cli wrapper, and failure tests. Use whenever a script reads inputs, sheets or config and must fail early.

Jak działa

  1. When to use
  2. Message format
  3. Steps
  4. Checks before finishing
  5. Pitfalls
Sekcje z nagłówków SKILL.md, w oryginale · 62 linii, 493 słów
Podgląd SKILL.md
---
name: python-validation-errors
description: 'Implement strict input validation and error/log messages in Python: ERROR/WARNING/INFO prefixes on stderr, exit codes, messages that name file, record, expected, observed and fix, collect-then-report validators, an error class with run_cli wrapper, and failure tests. Use whenever a script reads inputs, sheets or config and must fail early.'
---

# Strict validation and error messages

Purpose: an error is better than a wrong result. A user must be able to fix the problem from the
message alone, without reading code.

## When to use

Any script reading sample sheets, config, VCF/BED/tables, or manually maintained files. Check all
inputs before writing any output.

## Message format

`ERROR: <file>: <what is wrong> (expected <X>, found <Y>); <how to fix>`

Example: `ERROR: sheet.tsv: line 4: tumor_id 'TUMOR1' not found (samples in the VCF: TUMOR, NORMAL); check tumor_id in the sample sheet`.

Prefixes `ERROR:`, `WARNING:`, `INFO:` go to stderr. Exit codes: 0 ok, 1 error, 2 blocked / not ready
(missing prerequisite, used by orchestration). Never print a traceback for an expected failure.

## Steps

1. **Pick the mechanism.**
   - Simple script: `sys.exit(f"ERROR: ...")` (stderr, exit 1).
   - Several scripts or a package: an exception class carrying the parts, plus a wrapper:
     ```python
     class ToolError(Exception):
         def __init__(self, message, *, file=None, record=None, expected=None, observed=None, fix=None):
             parts = [message]
             for key, val in (("file", file), ("record", record), ("expected", expected),
                              ("observed", observed), ("fix", fix)):
                 if val is not None:
                     parts.append(f"{key}: {val!r}" if key == "observed" else f"{key}: {val}")
             super().__init__(" | ".join(parts))

     def run_cli(main):
         try:
             main()
         except ToolError as err:
             logging.getLogger("tool").error("ERROR: %s", err)
             sys.exit(1)
     ```
     `setup_logging(verbose)` logs to stderr with `%(asctime)s %(levelname)s %(message)s`, datefmt `%Y-%m-%dT%H:%M:%S`. With `logging` keep the `ERROR:` text prefix so output is greppable.
   - Sheet validation: an error collector with `warn()`, `error()`, `report_and_exit_on_error()`: print all warnings, then all errors, then `N problem(s) found, see above. Fix the sheet and run again.`, exit 1. Use it when many rows can be wrong at once.
2. **Order of checks:** file exists and readable, not empty, header present and delimiter right, required columns, removed/unknown columns (removed: error with "use X instead"; unknown: WARNING), then per-row checks with line numbers (header is line 1), then cross-row checks (duplicates, pairs).
3. **Strip and normalise** whitespace in manually maintained tables before checking; report each automatic fix (see `python-provenance-checks`, corrections table).
4. **Fallbacks:** if a fallback is intended (AF used when AD is missing) log `INFO:` once with the count and write the count to the summary; never fall back silently.
5. **Switches:** a check that can be disabled by a param turns its errors into `WARNING:`; the default stays strict.
6. **Tests:** one test per check; use `pytest.mark.parametrize` over (mutation, expected message fragment); assert exit code != 0 and the `ERROR:` fragment in stderr; add a test that valid input passes with no WARNING.

## Checks before finishing

- Every message names the file and, where possible, the record/line and the fix.
- No bare `raise ValueError("bad")` or `assert` for user input.
- stdout carries only data; diagnostics are on stderr.

## Pitfalls

- Reporting only the first error when the user must run again for each; collect.
- Catching `Exception` broadly and hiding the cause.
- Messages that print real IDs in logs shared outside the project; check what a message exposes.

Wersje

W bazie nie ma innych skilli o nazwie python-validation-errors.

Migawka bazy z 13.11.2026 · wersja paczki 1e13bf7bda6a (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100error-handling
    Opisuje wzorce solidnej obsługi błędów w TypeScript, Python i Go: typowane błędy, error boundaries, retry, circuit breakers i komunikaty o błędach dla użytkownika.
  • 100python-error-handling
    Pomaga zaprojektować obsługę błędów w Pythonie: walidację wejścia, hierarchię wyjątków i częściowe awarie w przetwarzaniu wsadowym.
  • 100build-cli-project
    Implementuje narzędzia wiersza poleceń w Rust po wyborze kształtu projektu: parsowanie argumentów, dyspozytor poleceń, stdin, stdout i stderr, kody wyjścia, konfiguracja, komunikaty błędów, testy i walidacja Cargo.
  • 100error-handling
    Pokazuje wzorce obsługi błędów w TypeScript, Pythonie i Go: typowane błędy, ponawianie, wyłączniki obwodu i komunikaty dla użytkownika.
  • 100python-cli-tools
    Buduje narzędzia wiersza poleceń w Python z poprawnymi kodami wyjścia, rozdziałem strumieni i punktem wejścia do dystrybucji, także przy pakowaniu CLI.
  • 100python-error-handling
    Stosuje wzorce obsługi błędów w Python: walidacja wejścia, hierarchie wyjątków i częściowe awarie przy przetwarzaniu wsadowym oraz w odpornych API.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.