Skip to content

Commit 421659e

Browse files
committed
fix: return None instead of re-raising on invalid YAML in existing dependabot 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>
1 parent f1a2991 commit 421659e

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

dependabot_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def build_dependabot_file(
251251
dependabot_file = yaml.load(base64.b64decode(existing_config.content))
252252
except ruamel.yaml.YAMLError as e:
253253
print(f"YAML indentation error: {e}")
254-
raise
254+
return None
255255
else:
256256
dependabot_file = copy.deepcopy(data)
257257

test_dependabot_file.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ def test_build_dependabot_file_with_2_space_indent_existing_config_bundler_with_
131131
)
132132
self.assertEqual(result, expected_result)
133133

134+
def test_build_dependabot_file_with_duplicate_key_in_existing_config(self):
135+
"""Test that a duplicate key in existing dependabot config returns None instead of crashing"""
136+
repo = MagicMock()
137+
repo.file_contents.side_effect = lambda f, filename="Gemfile": f == filename
138+
139+
existing_config = MagicMock()
140+
existing_config.content = base64.b64encode(b"""
141+
version: 2
142+
updates:
143+
- package-ecosystem: "maven"
144+
directory: "/"
145+
schedule:
146+
interval: "daily"
147+
schedule:
148+
interval: "weekly"
149+
day: "friday"
150+
""")
151+
152+
result = build_dependabot_file(
153+
repo, False, [], {}, existing_config, "weekly", "", [], None
154+
)
155+
self.assertIsNone(result)
156+
134157
def test_build_dependabot_file_with_weird_space_indent_existing_config_bundler_with_update(
135158
self,
136159
):
@@ -152,10 +175,10 @@ def test_build_dependabot_file_with_weird_space_indent_existing_config_bundler_w
152175
prefix: "chore(deps)"
153176
""")
154177

155-
with self.assertRaises(ruamel.yaml.YAMLError):
156-
build_dependabot_file(
157-
repo, False, [], {}, existing_config, "weekly", "", [], None
158-
)
178+
result = build_dependabot_file(
179+
repo, False, [], {}, existing_config, "weekly", "", [], None
180+
)
181+
self.assertIsNone(result)
159182

160183
def test_build_dependabot_file_with_incorrect_indentation_in_extra_dependabot_config_file(
161184
self,

0 commit comments

Comments
 (0)