Skip to content

Commit b0d7e49

Browse files
committed
fix(sandbox): satisfy repo lint rules in orca recipe
errcheck runs with check-blank, so blank-assigned errors need an explicit nolint and a reason. Reuse the outer err instead of shadowing it, and drop the client argument orcaInstallAgents stopped using when agent installs moved from the exec API to SSH. No behaviour change.
1 parent 8581444 commit b0d7e49

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

cmd/sandbox/orca.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func orcaCreate(c *cli.Context) error {
326326
orcaLog("WARNING destroy of %s failed: %v", id, rmErr)
327327
orcaLog("WARNING %s may still exist. Remove it with: createos sandbox rm --force %s", id, id)
328328
}
329-
_, _ = removeSSHBlock(sshAlias(id))
329+
_, _ = removeSSHBlock(sshAlias(id)) //nolint:errcheck // best-effort cleanup; the create error is what matters
330330
removeDedicatedKey(sshAlias(id))
331331
return err
332332
}
@@ -358,7 +358,7 @@ func orcaProvision(c *cli.Context, client *api.SandboxClient, id, repoPath, root
358358
if err := orcaSeedRepo(c, client, id, repoPath, root, branch); err != nil {
359359
return err
360360
}
361-
return orcaInstallAgents(c, client, id, agents)
361+
return orcaInstallAgents(c, id, agents)
362362
}
363363

364364
// orcaAgentNames lists the installable agents for help text and errors.
@@ -436,7 +436,7 @@ func orcaLastLine(s string) string {
436436
// devbox:1 ships some of these already, and re-running a vendor installer over
437437
// a good install is a needless minute and a needless failure mode, so each is
438438
// skipped when its binary already resolves.
439-
func orcaInstallAgents(c *cli.Context, client *api.SandboxClient, id string, agents []string) error {
439+
func orcaInstallAgents(c *cli.Context, id string, agents []string) error {
440440
alias := sshAlias(id)
441441
if !editorAliasRE.MatchString(alias) {
442442
return fmt.Errorf("refusing to run over shell-unsafe SSH alias %q", alias)
@@ -506,7 +506,7 @@ func orcaWireSSH(c *cli.Context, client *api.SandboxClient, id string, wait time
506506
return err
507507
}
508508

509-
if err := orcaWaitRunning(c.Context, client, id, wait); err != nil {
509+
if err = orcaWaitRunning(c.Context, client, id, wait); err != nil {
510510
return err
511511
}
512512
sb, err := client.GetSandbox(c.Context, id)
@@ -516,13 +516,13 @@ func orcaWireSSH(c *cli.Context, client *api.SandboxClient, id string, wait time
516516

517517
// The gateway authenticates against the sandbox row; the guest sshd reads
518518
// authorized_keys. The tunnel path needs both hops.
519-
if _, err := client.AddSSHPubkeys(c.Context, id, []string{strings.TrimSpace(string(pubBytes))}); err != nil {
519+
if _, err = client.AddSSHPubkeys(c.Context, id, []string{strings.TrimSpace(string(pubBytes))}); err != nil {
520520
return fmt.Errorf("could not register key with gateway: %w", err)
521521
}
522-
if err := ensureAuthorizedKey(c, client, id, orcaSSHUser, id, pubBytes, true); err != nil {
522+
if err = ensureAuthorizedKey(c, client, id, orcaSSHUser, id, pubBytes, true); err != nil {
523523
return fmt.Errorf("could not install key in guest: %w", err)
524524
}
525-
if err := startGuestSshd(c, client, id, orcaSSHUser); err != nil {
525+
if err = startGuestSshd(c, client, id, orcaSSHUser); err != nil {
526526
return err
527527
}
528528

@@ -591,14 +591,15 @@ func orcaSeedRepo(c *cli.Context, client *api.SandboxClient, id, repoPath, root,
591591
if err != nil {
592592
return fmt.Errorf("pack local state: %w", err)
593593
}
594-
defer func() { _ = os.Remove(tarPath) }() // #nosec G703 -- path is from os.CreateTemp, not user input.
594+
// #nosec G703 -- path is from os.CreateTemp, not user input.
595+
defer func() { _ = os.Remove(tarPath) }() //nolint:errcheck // removal failure is benign
595596
orcaLog("packed %d files, %s, in %s", fileCount, humanBytes(size), time.Since(packStart).Round(time.Second))
596597

597598
f, err := os.Open(tarPath) // #nosec G304,G703 -- path is from os.CreateTemp, not user input.
598599
if err != nil {
599600
return fmt.Errorf("open packed tar: %w", err)
600601
}
601-
defer func() { _ = f.Close() }()
602+
defer func() { _ = f.Close() }() //nolint:errcheck // read-only handle; close failure is benign
602603

603604
orcaLog("uploading %s to %s", humanBytes(size), id)
604605
uploadStart := time.Now()
@@ -664,16 +665,16 @@ func orcaBuildSeedTar(ctx context.Context, repoPath string) (string, int64, int,
664665
if err != nil {
665666
return "", 0, 0, err
666667
}
667-
defer func() { _ = tmp.Close() }()
668+
defer func() { _ = tmp.Close() }() //nolint:errcheck // explicit Close below owns the error
668669

669670
tw := tar.NewWriter(tmp)
670671
for _, rel := range paths {
671-
if err := orcaTarAppend(tw, repoPath, rel); err != nil {
672-
_ = tw.Close()
672+
if err = orcaTarAppend(tw, repoPath, rel); err != nil {
673+
_ = tw.Close() //nolint:errcheck // already unwinding a write error
673674
return "", 0, 0, err
674675
}
675676
}
676-
if err := tw.Close(); err != nil {
677+
if err = tw.Close(); err != nil {
677678
return "", 0, 0, err
678679
}
679680
info, err := tmp.Stat()
@@ -702,7 +703,7 @@ func orcaTarAppend(tw *tar.Writer, repoPath, rel string) error {
702703
return err
703704
}
704705
hdr.Name = rel
705-
if err := tw.WriteHeader(hdr); err != nil {
706+
if err = tw.WriteHeader(hdr); err != nil {
706707
return err
707708
}
708709
if link != "" || info.Size() == 0 {
@@ -712,7 +713,7 @@ func orcaTarAppend(tw *tar.Writer, repoPath, rel string) error {
712713
if err != nil {
713714
return nil //nolint:nilerr
714715
}
715-
defer func() { _ = f.Close() }()
716+
defer func() { _ = f.Close() }() //nolint:errcheck // read-only handle; close failure is benign
716717
_, err = io.Copy(tw, f)
717718
return err
718719
}
@@ -737,7 +738,7 @@ func orcaDestroy(c *cli.Context) error {
737738
if err := client.DestroySandbox(c.Context, id); err != nil {
738739
return fmt.Errorf("destroy %s: %w", id, err)
739740
}
740-
_, _ = removeSSHBlock(sshAlias(id))
741+
_, _ = removeSSHBlock(sshAlias(id)) //nolint:errcheck // best-effort cleanup
741742
removeDedicatedKey(sshAlias(id))
742743
orcaLog("destroyed %s", id)
743744
return nil

cmd/sandbox/orca_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestOrcaRejectsArgumentInjectionInHeadAndRef(t *testing.T) {
1313
bad := []string{
1414
"--upload-pack=touch /tmp/pwned",
1515
"-oProxyCommand=touch /tmp/pwned",
16-
strings.Repeat("a", 40)+" --upload-pack=x",
16+
strings.Repeat("a", 40) + " --upload-pack=x",
1717
"HEAD",
1818
"refs/heads/main",
1919
"",

0 commit comments

Comments
 (0)