Fix unhelpful message when a metadata file (fixes #1145)#1150
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 11 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughIntroduce a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG.rst`:
- Line 16: The changelog line "* Fix unhelpful message when a metadata file
(`#1145`)" is incomplete; update that entry (the line containing that exact text)
to a complete sentence such as "Fix unhelpful error message when a metadata file
is missing or malformed (`#1145`)" so the release note clearly describes the bug
and resolution.
In `@dfetch/project/metadata.py`:
- Around line 91-94: Introduce a new InvalidMetadataError exception and modify
Metadata.from_file (the try block that does
yaml.safe_load(metadata_file)["dfetch"]) to raise InvalidMetadataError for YAML
errors, for non-dict YAML results, and when the top-level "dfetch" key is
missing (wrap KeyError/TypeError into InvalidMetadataError and preserve the
original exception via "from"). Then update every caller that currently only
catches FileNotFoundError or (TypeError, ValueError) to catch
InvalidMetadataError instead—i.e., the places that call Metadata.from_file (the
stdout reporter, the report command handler, and the subproject metadata-loading
methods) so they handle invalid metadata consistently.
In `@features/handle-invalid-metadata.feature`:
- Around line 9-31: Duplicate or extend the existing "Metadata with invalid YAML
syntax is treated as invalid" scenario so it also exercises the `dfetch check`
command (in addition to `dfetch update`); either add a second Scenario that
mirrors the current steps but runs When I run "dfetch check" and asserts the
same diagnostic lines about ".dfetch_data.yaml is an invalid metadata file..."
in the Then block, or convert the scenario into a Scenario Outline with an
Examples table for the two commands ("dfetch update", "dfetch check") to ensure
both paths trigger the same error messages.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: ec46388b-5ce2-46a1-a4cb-2a1a15e066bb
📒 Files selected for processing (5)
CHANGELOG.rstdfetch/project/metadata.pydfetch/project/subproject.pyfeatures/handle-invalid-metadata.featurefeatures/steps/generic_steps.py
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@dfetch/project/metadata.py`:
- Around line 95-102: The loaded YAML value for "dfetch" may be non-mapping
(list, scalar, None), which later causes an AttributeError in Metadata.__init__;
before calling cls(data) (the class constructor invoked by return cls(data)),
validate that data is a mapping/dict (e.g., isinstance(data, dict) or
collections.abc.Mapping) and raise InvalidMetadataError with a clear message if
not; place this check immediately after data: Options =
yaml.safe_load(metadata_file)["dfetch"] and before return cls(data) so malformed
YAML produces InvalidMetadataError instead of leaking AttributeError from
__init__.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: 47fbc723-9d59-421f-8888-a1f12c31b052
📒 Files selected for processing (6)
CHANGELOG.rstdfetch/commands/report.pydfetch/project/metadata.pydfetch/project/subproject.pydfetch/reporting/stdout_reporter.pyfeatures/handle-invalid-metadata.feature
Fix #1145
Summary by CodeRabbit