Skip to content

fix: handle invalid YAML in existing dependabot config gracefully#526

Merged
jmeridth merged 5 commits intomainfrom
jm_handle_yaml_errors_gracefully
Mar 31, 2026
Merged

fix: handle invalid YAML in existing dependabot config gracefully#526
jmeridth merged 5 commits intomainfrom
jm_handle_yaml_errors_gracefully

Conversation

@jmeridth
Copy link
Copy Markdown
Collaborator

Pull Request

Proposed Changes

Fixes #523

What

Changed build_dependabot_file() to return None instead of re-raising when an existing dependabot config has invalid YAML (e.g., duplicate keys, indentation errors). Updated existing test expectations and added a new test for the duplicate key scenario reported in the issue.

Why

When a repository had an invalid dependabot.yml (such as a duplicate key), the YAML parse error crashed the entire program, preventing all remaining repositories from being processed. Returning None allows the caller's existing if dependabot_file is None check to skip the repo and continue to the next one.

Notes

  • The error message is still printed via the existing print(f"YAML indentation error: {e}") so users can identify which repo has a broken config.
  • The existing indentation error test also changed from assertRaises to assertIsNone since it exercises the same code path.

Testing

  • 156 tests pass with 99% code coverage.
  • Updated existing YAML indentation error test to expect None return instead of raised exception.
  • Added new test with a duplicate key scenario (matching the exact issue report) verifying build_dependabot_file() returns None.

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • run make lint and fix any issues that you have introduced
  • run make test and ensure you have test coverage for the lines you are introducing

@jmeridth jmeridth self-assigned this Mar 29, 2026
@github-actions github-actions bot added the fix label Mar 29, 2026
…pendabot config

Fixes #523

## What

Changed build_dependabot_file() to return None instead of re-raising when an existing dependabot config has invalid YAML (e.g., duplicate keys, indentation errors). Updated existing test expectations and added a new test for the duplicate key scenario reported in the issue.

## Why

When a repository had an invalid dependabot.yml (such as a duplicate key), the YAML parse error crashed the entire program, preventing all remaining repositories from being processed. Returning None allows the caller's existing `if dependabot_file is None` check to skip the repo and continue.

## Notes

- The error message is still printed via the existing `print(f"YAML indentation error: {e}")` so users can identify which repo has a broken config.
- The second test at line 175 (indentation error) also changed from `assertRaises` to `assertIsNone` since it exercises the same code path.

Signed-off-by: jmeridth <jmeridth@gmail.com>
## What

Moved the `if dependabot_file is None` check above the `yaml.dump()` call in `main()` so that None results skip immediately without writing `null` to `dependabot-output.yaml`.

## Why

The previous ordering called `yaml.dump(None, yaml_file)` before checking for None, writing a `null` YAML literal to the debug artifact. This was a pre-existing issue for the "no package managers" path, but the YAML error handling change made it newly reachable via the error path.

## Notes

- The YAML object and stream setup also moved below the guard since they're only needed when dependabot_file is not None.

Signed-off-by: jmeridth <jmeridth@gmail.com>
@jmeridth jmeridth force-pushed the jm_handle_yaml_errors_gracefully branch from 9d80cc6 to 2b558c4 Compare March 30, 2026 13:58
@jmeridth jmeridth added the Mark Ready When Ready Automatically mark draft PR ready when checks pass label Mar 30, 2026
@github-actions github-actions bot marked this pull request as ready for review March 30, 2026 14:02
@github-actions github-actions bot requested a review from zkoppert as a code owner March 30, 2026 14:02
@github-actions github-actions bot removed the Mark Ready When Ready Automatically mark draft PR ready when checks pass label Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@zkoppert zkoppert left a comment

Choose a reason for hiding this comment

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

Nice fix - the core approach of returning None instead of crashing is solid, and moving the None check before the yaml.dump calls is a good move.

Co-authored-by: Zack Koppert <zkoppert@github.com>
Signed-off-by: Jason Meridth <jmeridth@gmail.com>
Copilot AI review requested due to automatic review settings March 31, 2026 02:38
Copy link
Copy Markdown
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 aims to prevent the action from crashing when a repository’s existing dependabot.yml contains invalid YAML (e.g., indentation errors or duplicate keys), allowing processing to continue for subsequent repositories.

Changes:

  • Update build_dependabot_file() error handling for invalid existing Dependabot YAML and adjust expected behavior to return None.
  • Move the dependabot_file is None early-exit in evergreen.py to occur before attempting to dump YAML output.
  • Update/extend unit tests to cover invalid YAML scenarios, including a duplicate-key case.

Reviewed changes

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

File Description
dependabot_file.py Modifies YAML parse error handling when loading an existing Dependabot config.
evergreen.py Moves the None check earlier to avoid dumping None as YAML output.
test_dependabot_file.py Updates tests to expect None on invalid YAML and adds a duplicate-key regression test.

…dler

The UI merge of the error message suggestion accidentally replaced
`return None` with the new print line, leaving two print statements
and no early return. This caused UnboundLocalError on repos with
invalid YAML configs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: jmeridth <jmeridth@gmail.com>
…s None

## What

Change the print message from "No (new) compatible package manager found" to "Skipping repository" when `build_dependabot_file()` returns `None`.

## Why

`build_dependabot_file()` now returns `None` for two distinct reasons: no compatible package managers found, and a YAML parse error. The old message was only accurate for the first case and misleading for the second. Since the YAML error is already printed just before this point, a generic message avoids false attribution.

Signed-off-by: jmeridth <jmeridth@gmail.com>
Copy link
Copy Markdown

@Gaardsholt Gaardsholt left a comment

Choose a reason for hiding this comment

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

LGTM - I had similar approach in what I was playing around with locally, but I like your version better ;)

@jmeridth
Copy link
Copy Markdown
Collaborator Author

LGTM - I had similar approach in what I was playing around with locally, but I like your version better ;)

Thank you for the review. I will be more aware next time when someone files an issue and ask them if they want to do the PR first. 🙇

@jmeridth jmeridth merged commit cf9992e into main Mar 31, 2026
36 checks passed
@jmeridth jmeridth deleted the jm_handle_yaml_errors_gracefully branch March 31, 2026 19:30
@Gaardsholt
Copy link
Copy Markdown

LGTM - I had similar approach in what I was playing around with locally, but I like your version better ;)

Thank you for the review. I will be more aware next time when someone files an issue and ask them if they want to do the PR first. 🙇

Don't sweat it, as long as we find a solution for the issue at hand 👍

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.

Allow continuing even if a repo has yaml issues

4 participants