Skip to content

Cover input error messages#3537

Merged
koxudaxi merged 3 commits into
mainfrom
cover-input-error-messages
Jul 2, 2026
Merged

Cover input error messages#3537
koxudaxi merged 3 commits into
mainfrom
cover-input-error-messages

Conversation

@koxudaxi

@koxudaxi koxudaxi commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Tests
    • Added regression coverage for CLI error handling.
    • Verified exit codes and stderr diagnostics for malformed and missing input scenarios.
    • Included a tolerated malformed-input case to confirm successful completion.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fe9d071d-8368-4a3e-8e37-fdea6fb6dd85

📥 Commits

Reviewing files that changed from the base of the PR and between c848a7a and fd2ec04.

📒 Files selected for processing (1)
  • tests/main/test_error_messages.py

📝 Walkthrough

Walkthrough

Adds a new pytest module with parametrized cases covering CLI stderr diagnostics and exit codes for malformed input, missing input paths, and one tolerated malformed case.

Changes

Error message regression tests

Layer / File(s) Summary
Error message test suite
tests/main/test_error_messages.py
New test module with case tables and three parametrized tests asserting Exit.ERROR or Exit.OK and expected stderr content for malformed, missing, and tolerated input scenarios.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Related PRs: None found.

Suggested labels: tests

Suggested reviewers: koxudaxi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: added coverage for input error messages and related CLI diagnostics.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cover-input-error-messages

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Jul 2, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 21.59%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 11 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_perf_all_options_enabled 5.3 s 4.3 s +23.85%
WallTime test_perf_deep_nested 5.1 s 4.1 s +23.18%
WallTime test_perf_openapi_large 2.9 s 2.4 s +23.18%
WallTime test_perf_complex_refs 1.9 s 1.6 s +22.45%
WallTime test_perf_large_models_pydantic_v2 3.5 s 2.9 s +21.94%
WallTime test_perf_duplicate_names 1,022.1 ms 841.1 ms +21.53%
WallTime test_perf_multiple_files_input 3.4 s 2.8 s +21.2%
WallTime test_perf_stripe_style_pydantic_v2 1.9 s 1.6 s +20.46%
WallTime test_perf_kubernetes_style_pydantic_v2 2.5 s 2.1 s +20.39%
WallTime test_perf_graphql_style_pydantic_v2 770.3 ms 641.8 ms +20.01%
WallTime test_perf_aws_style_openapi_pydantic_v2 1.8 s 1.5 s +19.42%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing cover-input-error-messages (fd2ec04) with main (1af3514)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

📚 Docs Preview: https://pr-3537.datamodel-code-generator.pages.dev

Comment thread tests/main/test_error_messages.py Fixed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/main/test_error_messages.py (1)

45-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Simplify _input_file_type_id.

A match/case with a bind-and-return capture is more machinery than needed for a plain None-check.

♻️ Simpler alternative
-def _input_file_type_id(input_file_type: InputFileTypeLiteral | None) -> str:
-    match input_file_type:
-        case None:
-            return "auto"
-        case input_type:
-            return input_type
+def _input_file_type_id(input_file_type: InputFileTypeLiteral | None) -> str:
+    return "auto" if input_file_type is None else input_file_type
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/main/test_error_messages.py` around lines 45 - 50, Simplify
_input_file_type_id by replacing the match/case in
tests/main/test_error_messages.py with a direct None check, since the function
only maps None to "auto" and otherwise returns the provided
InputFileTypeLiteral. Keep the behavior identical, but make the logic in
_input_file_type_id more direct and readable by removing the bind-and-return
pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/main/test_error_messages.py`:
- Around line 37-40: The missing-path handling in the input-file validation path
is inconsistent: `jsonschema` still falls through to a traceback instead of the
same clean “File not found” message used for `None`. Update the logic around the
input-type selection and `FileNotFoundError` handling so the early missing-file
check applies to explicit `jsonschema` input too, and keep the expected
diagnostic aligned in `MISSING_INPUT_CASES` and the related error-reporting
flow.

---

Nitpick comments:
In `@tests/main/test_error_messages.py`:
- Around line 45-50: Simplify _input_file_type_id by replacing the match/case in
tests/main/test_error_messages.py with a direct None check, since the function
only maps None to "auto" and otherwise returns the provided
InputFileTypeLiteral. Keep the behavior identical, but make the logic in
_input_file_type_id more direct and readable by removing the bind-and-return
pattern.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1d8655de-a3d9-4b15-88a5-22906ce28744

📥 Commits

Reviewing files that changed from the base of the PR and between 4f20c04 and c848a7a.

⛔ Files ignored due to path filters (12)
  • tests/data/malformed/bad.graphql is excluded by !tests/data/**/*.graphql and included by none
  • tests/data/malformed/bad_openapi.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/dangling_local_ref.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/empty_jsonschema.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/enum_as_dict.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/missing_external_ref.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/non_dict_root.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/pointer_through_scalar.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/pointer_through_scalar_openapi.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/required_as_string.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/truncated_jsonschema.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/malformed/wrong_type_properties.json is excluded by !tests/data/**/*.json and included by none
📒 Files selected for processing (1)
  • tests/main/test_error_messages.py

Comment thread tests/main/test_error_messages.py
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4f20c04) to head (fd2ec04).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3537   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          160       161    +1     
  Lines        34295     34363   +68     
  Branches      4003      4011    +8     
=========================================
+ Hits         34295     34363   +68     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@koxudaxi koxudaxi merged commit 95a12c0 into main Jul 2, 2026
61 checks passed
@koxudaxi koxudaxi deleted the cover-input-error-messages branch July 2, 2026 07:35
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: PR #3537 is test-only. It adds malformed input fixtures under tests/data/malformed/ and a new regression test file tests/main/test_error_messages.py that pins the current stderr signals and exit codes for malformed/missing inputs. No source code, CLI options, Python API, Jinja2 templates, generated code output, default values, or error-handling logic were changed. The deleted-lines file is empty, so nothing was removed. All changes are additive test coverage, which cannot break existing users.


This analysis was performed by Claude Code Action

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🎉 Released in 0.67.0

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants