Skip to content

Commit 90c7d6a

Browse files
cfsmp3claude
andcommitted
fix: Improve error messages for missing build artifacts
Add _diagnose_missing_artifact function that checks workflow run status to provide specific error messages: - Build still in progress: tells user to wait and retry - Build failed: directs user to check GitHub Actions logs - Artifact expired: explains artifacts are deleted after retention period - No workflow run: indicates workflow wasn't triggered or is queued This helps users understand why their test couldn't start and what action to take. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 9bd40f2 commit 90c7d6a

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

mod_ci/controllers.py

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,62 @@ def mark_test_failed(db, test, repository, message: str) -> None:
467467
f"test is in inconsistent state!")
468468

469469

470+
def _diagnose_missing_artifact(repository, commit_sha: str, platform, log) -> str:
471+
"""
472+
Diagnose why an artifact was not found for a commit.
473+
474+
Checks the workflow run status to provide a more helpful error message.
475+
476+
:param repository: GitHub repository object
477+
:param commit_sha: The commit SHA to check
478+
:param platform: The platform (TestPlatform.linux or TestPlatform.windows)
479+
:param log: Logger instance
480+
:return: A descriptive error message
481+
"""
482+
from collections import defaultdict
483+
484+
if platform == TestPlatform.linux:
485+
expected_workflow = Workflow_builds.LINUX
486+
else:
487+
expected_workflow = Workflow_builds.WINDOWS
488+
489+
try:
490+
# Build workflow name lookup
491+
workflow = defaultdict(lambda: None)
492+
for active_workflow in repository.get_workflows():
493+
workflow[active_workflow.id] = active_workflow.name
494+
495+
# Check workflow runs for this commit
496+
workflow_found = False
497+
for workflow_run in repository.get_workflow_runs(head_sha=commit_sha):
498+
workflow_run_name = workflow[workflow_run.workflow_id]
499+
if workflow_run_name != expected_workflow:
500+
continue
501+
502+
workflow_found = True
503+
if workflow_run.status != "completed":
504+
return (f"Build still in progress: '{expected_workflow}' is {workflow_run.status}. "
505+
f"Please wait for the build to complete and retry.")
506+
elif workflow_run.conclusion != "success":
507+
return (f"Build failed: '{expected_workflow}' finished with conclusion '{workflow_run.conclusion}'. "
508+
f"Check the GitHub Actions logs for details.")
509+
else:
510+
# Build succeeded but artifact not found - may have expired
511+
return (f"Artifact not found: '{expected_workflow}' completed successfully, "
512+
f"but no artifact was found. The artifact may have expired (GitHub deletes "
513+
f"artifacts after a retention period) or was not uploaded properly.")
514+
515+
if not workflow_found:
516+
return (f"No workflow run found: '{expected_workflow}' has not run for commit {commit_sha[:7]}. "
517+
f"This may indicate the workflow was not triggered or is queued.")
518+
519+
except Exception as e:
520+
log.warning(f"Failed to diagnose missing artifact: {e}")
521+
return f"No build artifact found for this commit (diagnostic check failed: {e})"
522+
523+
return "No build artifact found for this commit"
524+
525+
470526
def start_test(compute, app, db, repository: Repository.Repository, test, bot_token) -> None:
471527
"""
472528
Start a VM instance and run the tests.
@@ -603,10 +659,10 @@ def start_test(compute, app, db, repository: Repository.Repository, test, bot_to
603659
artifact = find_artifact_for_commit(repository, test.commit, test.platform, log)
604660

605661
if artifact is None:
606-
log.critical(f"Test {test.id}: Could not find artifact for commit {test.commit[:8]}")
607-
mark_test_failed(db, test, repository,
608-
f"No build artifact found for commit {test.commit[:8]}. "
609-
"The artifact may have expired or the build may have failed.")
662+
# Use diagnostic function to provide detailed error message
663+
error_detail = _diagnose_missing_artifact(repository, test.commit, test.platform, log)
664+
log.critical(f"Test {test.id}: Could not find artifact for commit {test.commit[:8]}: {error_detail}")
665+
mark_test_failed(db, test, repository, error_detail)
610666
return
611667

612668
log.info(f"Test {test.id}: Found artifact '{artifact.name}' (ID: {artifact.id})")

0 commit comments

Comments
 (0)