Skip to content

fix(azuredevops_go): handle empty/invalid timeline responses for YAML…#8839

Open
techdecline wants to merge 2 commits intoapache:mainfrom
techdecline:fix/azuredevops-go-yaml-error-timeline
Open

fix(azuredevops_go): handle empty/invalid timeline responses for YAML…#8839
techdecline wants to merge 2 commits intoapache:mainfrom
techdecline:fix/azuredevops-go-yaml-error-timeline

Conversation

@techdecline
Copy link
Copy Markdown

@techdecline techdecline commented Apr 16, 2026

…-broken builds

Builds that fail due to YAML syntax errors in pipeline definitions return an empty or non-JSON body from the Timeline API (200 OK with no usable content). Previously this caused ParseRawMessageFromRecords to propagate a hard error that aborted the entire collectApiTimelineRecords subtask.

Two complementary fixes:

  1. Add ignoreInvalidTimelineResponse AfterResponse handler that supersedes ignoreDeletedBuilds: it still skips 404s (deleted builds) and now also skips responses with empty or non-JSON bodies by returning api.ErrIgnoreAndContinue, leaving the rest of the pipeline intact. The body is peeked and then restored via io.NopCloser so the downstream ResponseParser can still read it when the body is valid JSON.

  2. Extend the DB query in CollectRecords to exclude builds with result = 'none' in addition to result = 'failed'. Builds broken by YAML syntax errors are categorised as 'none' by Azure DevOps (already mapped to RESULT_FAILURE in cicdBuildResultRule), so fetching their timeline is both unnecessary and the primary source of the bad responses. Using NOT IN ? with a []string slice follows the same pattern used in blueprint_helper.go.

Unit tests added for ignoreInvalidTimelineResponse covering: 404, empty body, non-JSON body, valid JSON (nil error + body restored), and valid empty JSON object.

Fixes: #8838

⚠️ Pre Checklist

Please complete ALL items in this checklist, and remove before submitting

  • I have read through the Contributing Documentation.
  • I have added relevant tests.
  • I have added relevant documentation.
  • I will add labels to the PR, such as pr-type/bug-fix, pr-type/feature-development, etc.

Summary

What does this PR do?

Does this close any open issues?

Closes xx

Screenshots

Include any relevant screenshots here.

Other Information

Any other information that is important to this PR.

…-broken builds

Builds that fail due to YAML syntax errors in pipeline definitions return
an empty or non-JSON body from the Timeline API (200 OK with no usable
content). Previously this caused ParseRawMessageFromRecords to propagate
a hard error that aborted the entire collectApiTimelineRecords subtask.

Two complementary fixes:

1. Add ignoreInvalidTimelineResponse AfterResponse handler that supersedes
   ignoreDeletedBuilds: it still skips 404s (deleted builds) and now also
   skips responses with empty or non-JSON bodies by returning
   api.ErrIgnoreAndContinue, leaving the rest of the pipeline intact.
   The body is peeked and then restored via io.NopCloser so the downstream
   ResponseParser can still read it when the body is valid JSON.

2. Extend the DB query in CollectRecords to exclude builds with
   result = 'none' in addition to result = 'failed'. Builds broken by
   YAML syntax errors are categorised as 'none' by Azure DevOps (already
   mapped to RESULT_FAILURE in cicdBuildResultRule), so fetching their
   timeline is both unnecessary and the primary source of the bad
   responses. Using NOT IN ? with a []string slice follows the same
   pattern used in blueprint_helper.go.

Unit tests added for ignoreInvalidTimelineResponse covering: 404,
empty body, non-JSON body, valid JSON (nil error + body restored),
and valid empty JSON object.

Fixes: apache#8838
Signed-off-by: Cornelius Schuchardt <cornelius.schuchardt@beck.de>
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug labels Apr 16, 2026
@klesh
Copy link
Copy Markdown
Contributor

klesh commented Apr 18, 2026

Hi, can you fix the golang lint so I can merge it?

The ignoreDeletedBuilds function was replaced by
ignoreInvalidTimelineResponse
in ci_cd_timeline_records_collector.go but was left behind in shared.go.
This caused the 'unused' linter to fail with exit code 2.
@techdecline
Copy link
Copy Markdown
Author

Hi @klesh , I just pushed a fix for the linting error.

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

Labels

component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][azuredevops_go] YAML Syntax Error breaks Pipeline

2 participants