Skip to content

Update Precacher to No Longer Fatally Error by Default #14013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.0-dev
Choose a base branch
from

Conversation

sameluch
Copy link
Contributor

@sameluch sameluch commented Jun 16, 2025

Merge Checklist

All boxes should be checked before merging the PR (just tick any boxes which don't apply to this PR)

  • The toolchain has been rebuilt successfully (or no changes were made to it)
  • The toolchain/worker package manifests are up-to-date
  • Any updated packages successfully build (or no packages were changed)
  • Packages depending on static components modified in this PR (Golang, *-static subpackages, etc.) have had their Release tag incremented.
  • Package tests (%check section) have been verified with RUN_CHECK=y for existing SPEC files, or added to new SPEC files
  • All package sources are available
  • cgmanifest files are up-to-date and sorted (./cgmanifest.json, ./toolkit/scripts/toolchain/cgmanifest.json, .github/workflows/cgmanifest.json)
  • LICENSE-MAP files are up-to-date (./LICENSES-AND-NOTICES/SPECS/data/licenses.json, ./LICENSES-AND-NOTICES/SPECS/LICENSES-MAP.md, ./LICENSES-AND-NOTICES/SPECS/LICENSE-EXCEPTIONS.PHOTON)
  • All source files have up-to-date hashes in the *.signatures.json files
  • sudo make go-tidy-all and sudo make go-test-coverage pass
  • Documentation has been updated to match any changes to the build system
  • Ready to merge

Summary

What does the PR accomplish, why was it needed?
The precacher is not required for a build to complete, even if enabled. This change allows the precacher to fail without causing the build to fail in tandem.
The precacher should not be blocking builds which it is enabled for.

Change Log
  • Update precacher to run in new non-fatal mode by default
    • PRECACHER_NON_FATAL set to y by default
  • Add option PRECACHER_NON_FATAL to maintain current precacher behavior
Does this affect the toolchain?

NO

Test Methodology
  • Add small go snippet to network.go to simulate network failures during precacher
	if rand.Intn(100) == 0 {
		return false, fmt.Errorf("test failure: download failed intentionally")
	}
  • run test using lkg toolchain with the following command
    sudo make build-packages REBUILD_TOOLCHAIN=n REBUILD_TOOLS=y SRPM_PACK_LIST=words PACKAGE_REBUILD_LIST=words -j100 PRECACHE=y
  • Additionally run the following command to ensure the that fatal errors are still existant:
    sudo make build-packages REBUILD_TOOLCHAIN=n REBUILD_TOOLS=y SRPM_PACK_LIST=words PACKAGE_REBUILD_LIST=words -j100 PRECACHE=y PRECACHER_NON_FATAL=n

…tal version

update precacher for non-fatal error mode

turn on non-fatal precacher by default
@sameluch sameluch requested a review from a team as a code owner June 16, 2025 23:22
@microsoft-github-policy-service microsoft-github-policy-service bot added Tools 3.0-dev PRs Destined for AzureLinux 3.0 labels Jun 16, 2025
@dmcilvaney dmcilvaney requested a review from Copilot June 17, 2025 23:25
Copy link
Contributor

@Copilot 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 introduces a non-fatal mode for the precacher so that failures are logged without aborting the build by default.

  • Add a --non-fatal-mode flag and update error handlers in precacher.go
  • Change download errors to warn and continue, resetting errors for summary generation
  • Update precache.mk and Makefile to enable non-fatal mode by default

Reviewed Changes

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

File Description
toolkit/tools/precacher/precacher.go Add nonFatalMode flag and adjust error handling to optionally log errors instead of exiting
toolkit/scripts/precache.mk Pass --non-fatal-mode flag based on PRECACHER_NON_FATAL
toolkit/Makefile Set PRECACHER_NON_FATAL to y by default for non-fatal behavior
Comments suppressed due to low confidence (1)

toolkit/tools/precacher/precacher.go:65

  • [nitpick] Non-fatal mode behavior isn't covered by existing tests. Consider adding unit or integration tests to verify that errors are logged and the tool exits successfully when PRECACHER_NON_FATAL is enabled, and exits with non-zero when disabled.
	nonFatalMode     = app.Flag("non-fatal-mode", "Run in non-fatal mode, where errors are logged but do not cause the program to exit with a non-zero code.").Bool()

Comment on lines +111 to +115
logger.Log.Warnf("Package download failed")
logger.Log.Warnf("Missing package download failed: %s", err)
// reset the error to nil so we can still write the summary file
// packages which are not able to be downloaded are not considered a failure of the tool, just a failure to download some packages
err = nil
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

The downloadMissingPackages error handling unconditionally resets err to nil, ignoring nonFatalMode. In fatal mode, download failures should cause the program to exit, but currently they always result in a warning. Wrap this block in a nonFatalMode check similar to other error handlers.

Suggested change
logger.Log.Warnf("Package download failed")
logger.Log.Warnf("Missing package download failed: %s", err)
// reset the error to nil so we can still write the summary file
// packages which are not able to be downloaded are not considered a failure of the tool, just a failure to download some packages
err = nil
if *nonFatalMode {
logger.Log.Warnf("Package download failed")
logger.Log.Warnf("Missing package download failed: %s", err)
// reset the error to nil so we can still write the summary file
// packages which are not able to be downloaded are not considered a failure of the tool, just a failure to download some packages
err = nil
} else {
logger.FatalOnError(err)
}

Copilot uses AI. Check for mistakes.

@@ -80,11 +81,22 @@ func main() {

rpmSnapshot, err := rpmSnapshotFromFile(*snapshot)
if err != nil {
logger.PanicOnError(err)
if *nonFatalMode {
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

[nitpick] The non-fatal error handling logic is duplicated in multiple places. Consider extracting a helper function (e.g., handleError(err)) to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0-dev PRs Destined for AzureLinux 3.0 Tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants