Skip to content

Show precise location for config parsing error#1530

Merged
j178 merged 1 commit intomasterfrom
config-error-message
Feb 2, 2026
Merged

Show precise location for config parsing error#1530
j178 merged 1 commit intomasterfrom
config-error-message

Conversation

@j178
Copy link
Owner

@j178 j178 commented Feb 2, 2026

Finally, we can actually fix #783, big thanks to serde‑saphyr and @bourumir-wyngs!

For this invalid config:

repos:
  - repo: 'https://github.com/pre-commit/pre-commit-hooks'
    rev: v6.0.0
    hooks:
      - id: trailing-whitespace
      - name: end-of-file-fixer
      - id: check-yaml
      - id: check-added-large-files

Before:

prek validate-config .pre-commit-config.yaml
error: Failed to parse `.pre-commit-config.yaml`
  caused by: Invalid remote repo: missing field `id`

After:

~/code/rust/prek/target/debug/prek validate-config .pre-commit-config.yaml
error: Failed to parse `.pre-commit-config.yaml`
  caused by: error: line 6 column 9: missing field `id` at line 6, column 9
 --> <input>:6:9
  |
4 |     hooks:
5 |       - id: trailing-whitespace
6 |       - name: end-of-file-fixer
  |         ^ missing field `id` at line 6, column 9
7 |       - id: check-yaml
8 |       - id: check-added-large-files
  |

Copilot AI review requested due to automatic review settings February 2, 2026 09:57
@j178 j178 added the enhancement New feature or request label Feb 2, 2026
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 91.72932% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.57%. Comparing base (b070282) to head (a37537f).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/config.rs 88.08% 33 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1530      +/-   ##
==========================================
- Coverage   91.93%   91.57%   -0.37%     
==========================================
  Files          89       90       +1     
  Lines       18288    17882     -406     
==========================================
- Hits        16813    16375     -438     
- Misses       1475     1507      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 2, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (23.3 MiB → 23.3 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 72.4KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 69.2KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 64.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.8KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 43.3KiB              prek prek::run::{{closure}}
 0.2%   0.4% 41.5KiB              prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 32.0KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.4KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.3% 26.0KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.6KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 21.9KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.2KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.1KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 19.6KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.5KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.4KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map
 0.1%   0.2% 19.3KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.2KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
37.9%  91.3%  8.8MiB                   And 20502 smaller methods. Use -n N to show more.
41.6% 100.0%  9.7MiB                   .text section size, the file size is 23.3MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 75.6KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 70.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7% 65.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.8KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 43.3KiB              prek prek::run::{{closure}}
 0.2%   0.4% 41.7KiB              prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 31.7KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.4KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.3% 24.8KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.6KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.1KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.2KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.7KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 19.5KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.3KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
37.9%  91.3%  8.8MiB                   And 20592 smaller methods. Use -n N to show more.
41.5% 100.0%  9.7MiB                   .text section size, the file size is 23.3MiB

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines configuration parsing so that errors point to the precise location in the YAML, and it slightly relaxes some parsing (e.g., numeric rev values) while keeping strong validation. It also refactors schemars-related JSON schema generation into a dedicated module and updates tests and snapshots to cover the new behaviors.

Changes:

  • Replace the old Repo wire-format parsing with a custom Deserialize implementation that distinguishes local/meta/builtin/remote repos and produces detailed, field-level errors (e.g., missing rev, forbidden rev on local/meta/builtin, missing hook fields).
  • Improve type-tag and minimum-version error messages and add support for numeric rev values parsed as strings, with corresponding unit tests and insta snapshots for various repo/hook configurations and YAML merge-key scenarios.
  • Extract schemars JsonSchema implementations into a new schema module, wire it via the schemars feature, and update the mise generate task to run the CLI-reference and JSON-schema generators sequentially.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
mise.toml Updates the generate task to sequentially run the CLI-reference and JSON-schema generation subtasks using the run = [{ task = ... }] syntax.
crates/prek/tests/validate.rs Adjusts expected validate output to reflect the new, more precise config error messages and the acceptance of numeric rev values.
crates/prek/tests/install.rs Updates the install warning snapshot to match the new config parsing error text (dropping the old Invalid remote repo: prefix and pointing to the exact field location).
crates/prek/src/config.rs Refactors repo and hook parsing: adds Language as #[non_exhaustive], centralizes Formatter use, tightens serde attributes, replaces the Repo wire-type with a custom Deserialize visitor that enforces repo-kind-specific rules and produces precise error locations, tweaks type-tag and minimum-version error messages, and adds/updates unit tests and insta snapshots (including merge-key and numeric-rev cases).
crates/prek/src/schema.rs New module that houses schemars JsonSchema implementations for FilePattern, predefined hooks (MetaHook, BuiltinHook), repo kind schemas, and Repo, mirroring prior behavior but separating schema logic from config parsing.
crates/prek/src/main.rs Conditionally includes the new schema module under the schemars feature so JSON schema generation continues to work via the existing config test harness.
crates/prek/src/snapshots/prek__config__tests__read_config_with_nested_merge_keys.snap Adds snapshot for reading configs that use nested YAML merge keys, verifying the final Config structure.
crates/prek/src/snapshots/prek__config__tests__read_config_with_merge_keys.snap Adds snapshot for reading configs with top-level merge keys in repo hooks, ensuring merge resolution is reflected in Config.
crates/prek/src/snapshots/prek__config__tests__parse_repos.snap Snapshot for basic local repo parsing, confirming the Config shape with a simple local hook.
crates/prek/src/snapshots/prek__config__tests__parse_repos-2.snap Snapshot for local repo parsing that includes _unused_keys for extra fields, validating how unexpected keys are tracked.
crates/prek/src/snapshots/prek__config__tests__parse_repos-3.snap Snapshot for local repos with unknown fields at the repo level, ensuring _unused_keys is populated correctly.
crates/prek/src/snapshots/prek__config__tests__parse_repos-4.snap Snapshot for remote repo parsing with rev and minimal hook definitions, validating the RemoteRepo representation.
crates/prek/src/snapshots/prek__config__tests__parse_repos-6.snap Additional remote-repo snapshot (typos repo) confirming the structure of RemoteRepo and its hooks after parsing.
crates/prek/src/snapshots/prek__config__tests__parse_hooks-3.snap Snapshot for local hook parsing with explicit language, verifying the resulting Config/LocalHook structure.
crates/prek/src/snapshots/prek__config__tests__numeric_rev_is_parsed_as_string.snap Snapshot proving that numeric rev values are parsed as strings in remote repos.
crates/prek/src/snapshots/prek__config__tests__meta_hooks-5.snap Snapshot for valid meta-hook configuration, ensuring predefined meta hooks expand into the expected MetaRepo/MetaHook structures.
crates/prek/src/snapshots/prek__config__tests__language_version.snap Snapshot for various language_version values on local hooks, confirming correct parsing and storage in HookOptions.

Base automatically changed from serde-saphyr to master February 2, 2026 12:19
@j178 j178 enabled auto-merge (squash) February 2, 2026 12:20
@j178 j178 force-pushed the config-error-message branch from 6b03eec to a37537f Compare February 2, 2026 12:21
@j178 j178 disabled auto-merge February 2, 2026 12:32
@j178 j178 merged commit 7950d57 into master Feb 2, 2026
49 checks passed
@j178 j178 deleted the config-error-message branch February 2, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report line number for invalid config file error

2 participants