(cmd *cobra.Command)
| 261 | } |
| 262 | |
| 263 | func checkIfUpdateNeeded(cmd *cobra.Command) { |
| 264 | if shouldSkipUpdateCheck(cmd) { |
| 265 | return |
| 266 | } |
| 267 | |
| 268 | if os.Getenv("TNR_NO_SELFUPDATE") == "1" { |
| 269 | return |
| 270 | } |
| 271 | |
| 272 | ctx := context.Background() |
| 273 | |
| 274 | // Apply any previously staged Windows update before checking again. |
| 275 | if err := autoupdate.FinalizeWindowsSwap(); err != nil { |
| 276 | fmt.Fprintf(os.Stderr, "Warning: failed to finalize staged Windows update: %v\n", err) |
| 277 | } |
| 278 | |
| 279 | policyResult, err := updatepolicy.Check(ctx, version.BuildVersion, false) |
| 280 | if err != nil { |
| 281 | // Update checks hit external services (GitHub API). Any failure — |
| 282 | // timeouts, 5xx, network errors — is not actionable from Sentry. |
| 283 | fmt.Fprintf(os.Stderr, "Warning: update check failed: %v\n", err) |
| 284 | return |
| 285 | } |
| 286 | |
| 287 | if !policyResult.Mandatory && !policyResult.Optional { |
| 288 | return |
| 289 | } |
| 290 | |
| 291 | if policyResult.Mandatory { |
| 292 | handleMandatoryUpdate(ctx, policyResult, false) |
| 293 | return |
| 294 | } |
| 295 | |
| 296 | handleOptionalUpdate(ctx, policyResult) |
| 297 | } |
| 298 | |
| 299 | func handleMandatoryUpdate(parentCtx context.Context, res updatepolicy.Result, manual bool) { |
| 300 | displayCurrent := displayVersion(res.CurrentVersion) |
no test coverage detected