From 8911e699d81864f35164b58e17b83300f53ee94d Mon Sep 17 00:00:00 2001 From: joshp123 Date: Sat, 14 Feb 2026 18:36:27 -0800 Subject: [PATCH] fix: update-tools should not fail on nuked bird + robust nix prefetch parsing --- cmd/update-tools/main.go | 18 ++++++++++++------ internal/nix.go | 15 ++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cmd/update-tools/main.go b/cmd/update-tools/main.go index ebaa108..0647e16 100644 --- a/cmd/update-tools/main.go +++ b/cmd/update-tools/main.go @@ -13,10 +13,11 @@ import ( ) type Tool struct { - Name string - Repo string - Assets []AssetSpec - NixFile string + Name string + Repo string + Assets []AssetSpec + NixFile string + Optional bool } type AssetSpec struct { @@ -248,8 +249,9 @@ func main() { NixFile: filepath.Join(repoRoot, "nix", "pkgs", "sonoscli.nix"), }, { - Name: "bird", - Repo: "steipete/bird", + Name: "bird", + Repo: "steipete/bird", + Optional: true, // repo got nuked; keep packaging pinned, but don't fail the updater Assets: []AssetSpec{ {System: "aarch64-darwin", Regex: regexp.MustCompile(`bird-macos-universal-v[0-9.]+\.tar\.gz`)}, }, @@ -295,6 +297,10 @@ func main() { } for _, tool := range tools { if err := updateTool(tool); err != nil { + if tool.Optional { + log.Printf("[update-tools] skipping optional tool %s: %v", tool.Name, err) + continue + } log.Fatalf("update %s failed: %v", tool.Name, err) } } diff --git a/internal/nix.go b/internal/nix.go index 0e0c088..15bddfb 100644 --- a/internal/nix.go +++ b/internal/nix.go @@ -19,15 +19,16 @@ type PrefetchGitHubResult struct { func PrefetchHash(url string) (string, error) { cmd := exec.Command("nix", "store", "prefetch-file", "--json", url) - var out bytes.Buffer - cmd.Stdout = &out - cmd.Stderr = &out + var stdout bytes.Buffer + var stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr if err := cmd.Run(); err != nil { - return "", fmt.Errorf("prefetch failed: %v: %s", err, out.String()) + return "", fmt.Errorf("prefetch failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout.String(), stderr.String()) } var res PrefetchResult - if err := json.Unmarshal(out.Bytes(), &res); err != nil { - return "", err + if err := json.Unmarshal(stdout.Bytes(), &res); err != nil { + return "", fmt.Errorf("prefetch json parse failed: %v\nstdout:\n%s\nstderr:\n%s", err, stdout.String(), stderr.String()) } if res.Hash == "" { return "", fmt.Errorf("empty hash for %s", url) @@ -87,7 +88,7 @@ func NixBuildSummarizeSystem(system string) (string, error) { } func ExtractGotHash(log string) string { - re := regexp.MustCompile(`got:\s*(sha256-[A-Za-z0-9+/=]+)`) + re := regexp.MustCompile(`got:\s*(sha256-[A-Za-z0-9+/=]+)`) for _, line := range strings.Split(log, "\n") { match := re.FindStringSubmatch(line) if len(match) > 1 {