fix: return write-side close errors; the gate checks unhandled errors
This commit is contained in:
35 files changed
+132
-127
No files matched your search
@@ -154,7 +154,6 @@ linters:
|
||||
- ui/node_modules
|
||||
presets:
|
||||
- comments
|
||||
- std-error-handling
|
||||
- common-false-positives
|
||||
- legacy
|
||||
rules:
|
||||
|
||||
@@ -54,7 +54,7 @@ func runCommand(args []string, getenv func(string) string, stderr io.Writer, run
|
||||
|
||||
natsURL, natsToken := natsConnectionSettings(*natsURLFlag, getenv)
|
||||
if natsURL == "" {
|
||||
fmt.Fprintln(stderr, "error: -nats-url or NATS_URL is required")
|
||||
_, _ = fmt.Fprintln(stderr, "error: -nats-url or NATS_URL is required")
|
||||
flags.Usage()
|
||||
return 1
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func runCommand(args []string, getenv func(string) string, stderr io.Writer, run
|
||||
stateStoreURL = getenv("STATE_STORE_URL")
|
||||
}
|
||||
if stateStoreURL == "" {
|
||||
fmt.Fprintln(stderr, "error: -state-store-url or STATE_STORE_URL is required (the legacy NATS storerpc path is deleted)")
|
||||
_, _ = fmt.Fprintln(stderr, "error: -state-store-url or STATE_STORE_URL is required (the legacy NATS storerpc path is deleted)")
|
||||
flags.Usage()
|
||||
return 1
|
||||
}
|
||||
@@ -133,14 +133,14 @@ func runRelay(args []string, stderr io.Writer, serve relayServer) int {
|
||||
return 2
|
||||
}
|
||||
if len(forwards) == 0 {
|
||||
fmt.Fprintln(stderr, "error: at least one -forward is required")
|
||||
_, _ = fmt.Fprintln(stderr, "error: at least one -forward is required")
|
||||
flags.Usage()
|
||||
return 1
|
||||
}
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
if err := serve(ctx, forwards); err != nil {
|
||||
fmt.Fprintln(stderr, "error:", err)
|
||||
_, _ = fmt.Fprintln(stderr, "error:", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
|
||||
@@ -39,7 +39,7 @@ func run() int {
|
||||
flag.StringVar(&options.Listen, "listen", "", "state store gRPC listen address (defaults to [services.state].listen, else 127.0.0.1:9090)")
|
||||
flag.StringVar(&options.ReadyAddr, "ready-addr", "", "optional readiness HTTP listen address (e.g. 127.0.0.1:9091)")
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "usage: archie-state-store [flags] # serve the State Store gRPC contract\n\ndatabase roles: archie-state-store provision -h\noffline recovery: archie-state-store <backup|restore|validate|rollback> -h | access reset -h\n\n")
|
||||
_, _ = fmt.Fprintf(flag.CommandLine.Output(), "usage: archie-state-store [flags] # serve the State Store gRPC contract\n\ndatabase roles: archie-state-store provision -h\noffline recovery: archie-state-store <backup|restore|validate|rollback> -h | access reset -h\n\n")
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
@@ -47,7 +47,7 @@ the daemon boots with, which names the database.
|
||||
// 1 the operation failed, 2 the command line was wrong.
|
||||
func runRecovery(args []string, stdout, stderr io.Writer) int {
|
||||
if len(args) == 0 {
|
||||
fmt.Fprint(stderr, recoveryUsage)
|
||||
_, _ = fmt.Fprint(stderr, recoveryUsage)
|
||||
return 2
|
||||
}
|
||||
command := args[0]
|
||||
@@ -55,14 +55,14 @@ func runRecovery(args []string, stdout, stderr io.Writer) int {
|
||||
switch command {
|
||||
case statestore.RecoveryBackup, statestore.RecoveryRestore, statestore.RecoveryValidate, statestore.RecoveryRollback:
|
||||
default:
|
||||
fmt.Fprintf(stderr, "archie-state-store: unknown command %q\n\n", command)
|
||||
fmt.Fprint(stderr, recoveryUsage)
|
||||
_, _ = fmt.Fprintf(stderr, "archie-state-store: unknown command %q\n\n", command)
|
||||
_, _ = fmt.Fprint(stderr, recoveryUsage)
|
||||
return 2
|
||||
}
|
||||
|
||||
flags := flag.NewFlagSet("archie-state-store "+command, flag.ContinueOnError)
|
||||
flags.SetOutput(stderr)
|
||||
flags.Usage = func() { fmt.Fprint(stderr, recoveryUsage) }
|
||||
flags.Usage = func() { _, _ = fmt.Fprint(stderr, recoveryUsage) }
|
||||
flags.StringVar(&options.Out, "out", "", "snapshot file backup writes")
|
||||
flags.StringVar(&options.From, "from", "", "snapshot file restore reads")
|
||||
flags.StringVar(&options.Kind, "kind", "", "control-plane resource kind rollback replays")
|
||||
@@ -80,15 +80,15 @@ func runRecovery(args []string, stdout, stderr io.Writer) int {
|
||||
return 2
|
||||
}
|
||||
if flags.NArg() > 0 {
|
||||
fmt.Fprintf(stderr, "archie-state-store %s: unexpected argument %q\n", command, flags.Arg(0))
|
||||
_, _ = fmt.Fprintf(stderr, "archie-state-store %s: unexpected argument %q\n", command, flags.Arg(0))
|
||||
return 2
|
||||
}
|
||||
|
||||
summary, err := statestore.RunRecovery(context.Background(), options)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "archie-state-store %s: %v\n", command, err)
|
||||
_, _ = fmt.Fprintf(stderr, "archie-state-store %s: %v\n", command, err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintln(stdout, summary)
|
||||
_, _ = fmt.Fprintln(stdout, summary)
|
||||
return 0
|
||||
}
|
||||
@@ -24,7 +24,7 @@ const releaseUsage = `usage: archied release <command>
|
||||
// a source signs with and pushes signed releases to it.
|
||||
func RunRelease(args []string, out, stderr io.Writer) int {
|
||||
if len(args) == 0 {
|
||||
fmt.Fprintln(stderr, releaseUsage)
|
||||
_, _ = fmt.Fprintln(stderr, releaseUsage)
|
||||
return 2
|
||||
}
|
||||
switch args[0] {
|
||||
@@ -35,7 +35,7 @@ func RunRelease(args []string, out, stderr io.Writer) int {
|
||||
case "promote":
|
||||
return runReleasePromote(args[1:], out, stderr)
|
||||
default:
|
||||
fmt.Fprintln(stderr, releaseUsage)
|
||||
_, _ = fmt.Fprintln(stderr, releaseUsage)
|
||||
return 2
|
||||
}
|
||||
}
|
||||
@@ -50,17 +50,17 @@ func runReleaseKeygen(args []string, out, stderr io.Writer) int {
|
||||
return 2
|
||||
}
|
||||
if *seedPath == "" {
|
||||
fmt.Fprintln(stderr, "release keygen: -seed is required")
|
||||
_, _ = fmt.Fprintln(stderr, "release keygen: -seed is required")
|
||||
return 2
|
||||
}
|
||||
public, private, err := ed25519.GenerateKey(nil)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
file, err := os.OpenFile(*seedPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o600)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
_, err = fmt.Fprintln(file, base64.StdEncoding.EncodeToString(private.Seed()))
|
||||
@@ -68,10 +68,10 @@ func runReleaseKeygen(args []string, out, stderr io.Writer) int {
|
||||
err = closeErr
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintln(out, distribution.EncodeKey(public))
|
||||
_, _ = fmt.Fprintln(out, distribution.EncodeKey(public))
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -90,12 +90,12 @@ func runReleasePublish(args []string, out, stderr io.Writer) int {
|
||||
return 2
|
||||
}
|
||||
if req.Repository == "" || req.Version == "" || req.ZipPath == "" || req.AgentImage == "" {
|
||||
fmt.Fprintln(stderr, "release publish: -source, -version, -zip and -agent-image are required")
|
||||
_, _ = fmt.Fprintln(stderr, "release publish: -source, -version, -zip and -agent-image are required")
|
||||
return 2
|
||||
}
|
||||
seed, err := base64.StdEncoding.DecodeString(strings.TrimSpace(os.Getenv(*seedEnv)))
|
||||
if err != nil || len(seed) != ed25519.SeedSize {
|
||||
fmt.Fprintf(stderr, "release publish: %s must hold a base64 ed25519 seed\n", *seedEnv)
|
||||
_, _ = fmt.Fprintf(stderr, "release publish: %s must hold a base64 ed25519 seed\n", *seedEnv)
|
||||
return 2
|
||||
}
|
||||
req.Signer = ed25519.NewKeyFromSeed(seed)
|
||||
@@ -104,10 +104,10 @@ func runReleasePublish(args []string, out, stderr io.Writer) int {
|
||||
req.Channels = []string{"next"}
|
||||
statement, err := releaseupdate.Publish(context.Background(), req)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(out, "published %s to %s (%s) with key %s\n", statement.Version, req.Repository,
|
||||
_, _ = fmt.Fprintf(out, "published %s to %s (%s) with key %s\n", statement.Version, req.Repository,
|
||||
strings.Join(req.Channels, ", "), public)
|
||||
return 0
|
||||
}
|
||||
@@ -125,15 +125,15 @@ func runReleasePromote(args []string, out, stderr io.Writer) int {
|
||||
}
|
||||
source, err := distribution.Parse(*reference, *key, distribution.DefaultReleases())
|
||||
if err != nil || *version == "" {
|
||||
fmt.Fprintln(stderr, "release promote: -version is required, and -source with -key name another source")
|
||||
_, _ = fmt.Fprintln(stderr, "release promote: -version is required, and -source with -key name another source")
|
||||
return 2
|
||||
}
|
||||
statement, err := releaseupdate.Promote(context.Background(), source.Reference, source.Key, *version, splitList(*latest))
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(out, "stable is %s\n", statement.Version)
|
||||
_, _ = fmt.Fprintf(out, "stable is %s\n", statement.Version)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ func forgeGet(ctx context.Context, typ, host, token, path string, out any) error
|
||||
if err != nil {
|
||||
return errors.New("forge unavailable")
|
||||
}
|
||||
defer response.Body.Close()
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return errors.New("forge refused")
|
||||
}
|
||||
|
||||
@@ -196,30 +196,30 @@ func RunSetup(args []string, stdin *os.File, stdout, stderr io.Writer) int {
|
||||
return 2
|
||||
}
|
||||
if fs.NArg() > 0 {
|
||||
fmt.Fprintf(stderr, "setup: unexpected argument %q\n", fs.Arg(0))
|
||||
_, _ = fmt.Fprintf(stderr, "setup: unexpected argument %q\n", fs.Arg(0))
|
||||
return 2
|
||||
}
|
||||
params, err := flags.params()
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
return 2
|
||||
}
|
||||
p, err := setupPrompter(flags.defaults, stdin, stdout)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
cfgDir := filepath.Dir(flags.cfgPath)
|
||||
if err := os.MkdirAll(cfgDir, 0o700); err != nil {
|
||||
fmt.Fprintf(stderr, "setup: create config directory: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "setup: create config directory: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
sink := setup.NewEnvFileSink(filepath.Join(cfgDir, "env"))
|
||||
loader := configuration.New(nil)
|
||||
base, existing, err := existingConfig(loader, flags.cfgPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ func RunSetup(args []string, stdin *os.File, stdout, stderr io.Writer) int {
|
||||
|
||||
edits, err := setup.RunParams(ctx, p, nil, sink, existing, params)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -239,15 +239,15 @@ func RunSetup(args []string, stdin *os.File, stdout, stderr io.Writer) int {
|
||||
rendered, err = tomlwrite.Generate(configtemplate.Example, edits)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "setup: render config: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "setup: render config: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
if err := installValidatedConfig(loader, flags.cfgPath, sink, rendered); err != nil {
|
||||
fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "setup: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(stdout, "setup: wrote %s\n", flags.cfgPath)
|
||||
_, _ = fmt.Fprintf(stdout, "setup: wrote %s\n", flags.cfgPath)
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ func proveLoadable(loader *configuration.Loader, rendered []byte) error {
|
||||
return fmt.Errorf("prove config loads: %w", err)
|
||||
}
|
||||
name := tmp.Name()
|
||||
defer os.Remove(name)
|
||||
defer func() { _ = os.Remove(name) }()
|
||||
if err := tmp.Close(); err != nil {
|
||||
return fmt.Errorf("prove config loads: %w", err)
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ func RunStatus(args []string, stdout, stderr io.Writer) int {
|
||||
}
|
||||
_, doc, err := servicekit.Resolve(slog.New(slog.DiscardHandler), *cfgPath, *overlayPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "archied status: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "archied status: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "archied status: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "archied status: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
defer cleanup()
|
||||
@@ -40,18 +40,18 @@ func RunStatus(args []string, stdout, stderr io.Writer) int {
|
||||
defer cancel()
|
||||
records, err := client.ListPresence(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "archied status: state store unreachable: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "archied status: state store unreachable: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
now := time.Now()
|
||||
healthy := true
|
||||
w := tabwriter.NewWriter(stdout, 0, 0, 2, ' ', 0)
|
||||
fmt.Fprintln(w, "SERVICE\tSTATE\tVERSION\tUPTIME\tDETAIL")
|
||||
_, _ = fmt.Fprintln(w, "SERVICE\tSTATE\tVERSION\tUPTIME\tDETAIL")
|
||||
for _, service := range presence.Mesh(records, now) {
|
||||
if service.State != presence.StateUp {
|
||||
healthy = false
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", service.Service, service.State, orDash(service.Version), uptime(service, now), service.Detail)
|
||||
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", service.Service, service.State, orDash(service.Version), uptime(service, now), service.Detail)
|
||||
}
|
||||
_ = w.Flush()
|
||||
if !healthy {
|
||||
|
||||
@@ -45,7 +45,7 @@ const updateUsage = `usage:
|
||||
// agent-image points new tasks at an agent image built outside a release.
|
||||
func RunUpdate(args []string, out, stderr io.Writer) int {
|
||||
if len(args) == 0 {
|
||||
fmt.Fprintln(stderr, updateUsage)
|
||||
_, _ = fmt.Fprintln(stderr, updateUsage)
|
||||
return 2
|
||||
}
|
||||
switch args[0] {
|
||||
@@ -58,7 +58,7 @@ func RunUpdate(args []string, out, stderr io.Writer) int {
|
||||
case "agent-image":
|
||||
return runUpdateAgentImage(args[1:], out, stderr)
|
||||
default:
|
||||
fmt.Fprintln(stderr, updateUsage)
|
||||
_, _ = fmt.Fprintln(stderr, updateUsage)
|
||||
return 2
|
||||
}
|
||||
}
|
||||
@@ -73,21 +73,21 @@ func runUpdateAgentImage(args []string, out, stderr io.Writer) int {
|
||||
return 2
|
||||
}
|
||||
if flags.NArg() != 1 {
|
||||
fmt.Fprintln(stderr, updateUsage)
|
||||
_, _ = fmt.Fprintln(stderr, updateUsage)
|
||||
return 2
|
||||
}
|
||||
ctx := context.Background()
|
||||
policy := imagePolicy{configPath: *configPath}
|
||||
current, err := policy.Image(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
if err := policy.SetImage(ctx, current, flags.Arg(0)); err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(out, "agent image: %s -> %s\n", current, flags.Arg(0))
|
||||
_, _ = fmt.Fprintf(out, "agent image: %s -> %s\n", current, flags.Arg(0))
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -107,18 +107,18 @@ func runUpdateInstall(args []string, out, stderr io.Writer) int {
|
||||
}
|
||||
source, err := releases()
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 2
|
||||
}
|
||||
self, err := os.Executable()
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
ctx := context.Background()
|
||||
tx, err := hostTransaction(*configPath, filepath.Dir(self), func(line string) { fmt.Fprintln(out, line) })
|
||||
tx, err := hostTransaction(*configPath, filepath.Dir(self), func(line string) { _, _ = fmt.Fprintln(out, line) })
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
result, err := tx.Prepare(ctx, releaseupdate.PrepareRequest{
|
||||
@@ -128,24 +128,24 @@ func runUpdateInstall(args []string, out, stderr io.Writer) int {
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
frozen := filepath.Join(releaseupdate.JournalPath(updateStateDir()), releaseupdate.WatchdogBinary)
|
||||
if err := spawnWatchdog(ctx, result.RestartRequested, frozen, *configPath, false); err != nil {
|
||||
// The journal stays: the next archied boot recovers it.
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
if !result.RestartRequested {
|
||||
fmt.Fprintf(out, "no systemd user manager: the watchdog installs %s without restarting; restart the archie services to run it\n", *version)
|
||||
_, _ = fmt.Fprintf(out, "no systemd user manager: the watchdog installs %s without restarting; restart the archie services to run it\n", *version)
|
||||
}
|
||||
data, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintln(out, releaseupdate.ResultSentinel+string(data))
|
||||
_, _ = fmt.Fprintln(out, releaseupdate.ResultSentinel+string(data))
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -158,13 +158,13 @@ func runUpdateWatchdog(args []string, stderr io.Writer) int {
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return 2
|
||||
}
|
||||
tx, err := hostTransaction(*configPath, *binDir, func(line string) { fmt.Fprintln(stderr, line) })
|
||||
tx, err := hostTransaction(*configPath, *binDir, func(line string) { _, _ = fmt.Fprintln(stderr, line) })
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
if err := tx.Run(context.Background(), *recovering); err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
@@ -273,9 +273,9 @@ func checkUpdateTopology(ctx context.Context, configPath string, required releas
|
||||
if len(plan) == 0 {
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintln(out, "Required migration, in order:")
|
||||
_, _ = fmt.Fprintln(out, "Required migration, in order:")
|
||||
for _, step := range plan {
|
||||
fmt.Fprintln(out, " -", step)
|
||||
_, _ = fmt.Fprintln(out, " -", step)
|
||||
}
|
||||
if observeErr != nil {
|
||||
return fmt.Errorf("topology unknown; apply the printed migration before retrying: %w", observeErr)
|
||||
@@ -324,7 +324,7 @@ func updateOrphaned() (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer lock.Close()
|
||||
defer func() { _ = lock.Close() }()
|
||||
if err := unix.Flock(int(lock.Fd()), unix.LOCK_EX|unix.LOCK_NB); errors.Is(err, unix.EWOULDBLOCK) {
|
||||
// A live watchdog owns the transaction and is restarting this unit.
|
||||
return false, nil
|
||||
|
||||
@@ -25,7 +25,7 @@ func runUpdateCheck(args []string, out, stderr io.Writer) int {
|
||||
}
|
||||
source, err := releases()
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 2
|
||||
}
|
||||
catalog := &releaseupdate.RegistryCatalog{Settings: func(context.Context) (distribution.Source, string, string, error) {
|
||||
@@ -33,13 +33,13 @@ func runUpdateCheck(args []string, out, stderr io.Writer) int {
|
||||
}}
|
||||
snapshot, err := catalog.Check(context.Background())
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
encoder := json.NewEncoder(out)
|
||||
encoder.SetIndent("", " ")
|
||||
if err := encoder.Encode(snapshot); err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
_, _ = fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestResumeUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer lock.Close()
|
||||
defer func() { _ = lock.Close() }()
|
||||
if active {
|
||||
if err := unix.Flock(int(lock.Fd()), unix.LOCK_EX); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
// bound, the process declares itself serving, and the chat contract answers
|
||||
// until ctx ends.
|
||||
func (b *server) serveGatewayListener(ctx context.Context, listener net.Listener, contract gateway.ChatContract, opts []grpc.ServerOption) error {
|
||||
defer listener.Close()
|
||||
defer func() { _ = listener.Close() }()
|
||||
b.log.InfoContext(ctx, "archie-gateway running", "addr", listener.Addr().String(), "tls", b.id != nil)
|
||||
// Boot is over and this listener is about to accept: the same fact
|
||||
// systemd's READY=1 asserts, so the announcement goes out here rather than
|
||||
|
||||
@@ -118,7 +118,7 @@ func (g *publicGitHub) GetPullRequest(ctx context.Context, owner, repo string, n
|
||||
if err != nil {
|
||||
return prsource.PullRequest{}, err
|
||||
}
|
||||
defer body.Close()
|
||||
defer func() { _ = body.Close() }()
|
||||
var raw struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
@@ -141,7 +141,7 @@ func (g *publicGitHub) GetPullRequestDiff(ctx context.Context, owner, repo strin
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer body.Close()
|
||||
defer func() { _ = body.Close() }()
|
||||
data, err := io.ReadAll(body)
|
||||
return string(data), err
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ func Run(ctx context.Context, log *slog.Logger, opts Options, w io.Writer) (benc
|
||||
if err != nil {
|
||||
return summary, err
|
||||
}
|
||||
fmt.Fprint(w, report)
|
||||
fmt.Fprintf(w, "\nreport written to %s\n", path)
|
||||
_, _ = fmt.Fprint(w, report)
|
||||
_, _ = fmt.Fprintf(w, "\nreport written to %s\n", path)
|
||||
if summary.Failed != 0 {
|
||||
return summary, fmt.Errorf("%d benchmark problem(s) failed; results are incomplete", summary.Failed)
|
||||
}
|
||||
@@ -141,14 +141,14 @@ func Main(args []string, stdout, stderr io.Writer) int {
|
||||
}
|
||||
log, closer, err := logging.New(logging.Options{})
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, "archied prbench:", err)
|
||||
_, _ = fmt.Fprintln(stderr, "archied prbench:", err)
|
||||
return 1
|
||||
}
|
||||
defer closer.Close()
|
||||
defer func() { _ = closer.Close() }()
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
if _, err := Run(ctx, log, opts, stdout); err != nil {
|
||||
fmt.Fprintln(stderr, "archied prbench:", err)
|
||||
_, _ = fmt.Fprintln(stderr, "archied prbench:", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
|
||||
@@ -47,11 +47,11 @@ func RunAccessReset(ctx context.Context, args []string, stderr io.Writer) int {
|
||||
return 2
|
||||
}
|
||||
if fs.NArg() > 0 {
|
||||
fmt.Fprintf(stderr, "reset: unexpected argument %q\n", fs.Arg(0))
|
||||
_, _ = fmt.Fprintf(stderr, "reset: unexpected argument %q\n", fs.Arg(0))
|
||||
return 2
|
||||
}
|
||||
if (*orgFlag != "" && *instance) || (*orgFlag == "" && !*instance) {
|
||||
fmt.Fprintln(stderr, "reset: give exactly one of --org <org> or --instance")
|
||||
_, _ = fmt.Fprintln(stderr, "reset: give exactly one of --org <org> or --instance")
|
||||
return 2
|
||||
}
|
||||
|
||||
@@ -63,13 +63,13 @@ func RunAccessReset(ctx context.Context, args []string, stderr io.Writer) int {
|
||||
if err := b.openStateStorePool(ctx); err != nil {
|
||||
// A running State Store holds the ownership claim; the reset must not
|
||||
// race it. Stop the store, reset, start the store.
|
||||
fmt.Fprintln(stderr, "reset: open the State Store database (stop archie-state-store first)")
|
||||
_, _ = fmt.Fprintln(stderr, "reset: open the State Store database (stop archie-state-store first)")
|
||||
return 1
|
||||
}
|
||||
b.openTaskStore()
|
||||
resetter, ok := b.st.(access.Resetter)
|
||||
if !ok {
|
||||
fmt.Fprintln(stderr, "reset: the State Store does not support the access reset surface")
|
||||
_, _ = fmt.Fprintln(stderr, "reset: the State Store does not support the access reset surface")
|
||||
return 1
|
||||
}
|
||||
var err error
|
||||
@@ -80,14 +80,14 @@ func RunAccessReset(ctx context.Context, args []string, stderr io.Writer) int {
|
||||
err = resetter.ResetOrgPolicies(ctx, org.OrgID(*orgFlag))
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "reset: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "reset: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
if err := recordResetAudit(ctx, b.pg, *orgFlag, *instance); err != nil {
|
||||
fmt.Fprintf(stderr, "reset: audit: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "reset: audit: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(stderr, "reset: access policies for %s restored to the shipped set\n", resetTarget(*orgFlag, *instance))
|
||||
_, _ = fmt.Fprintf(stderr, "reset: access policies for %s restored to the shipped set\n", resetTarget(*orgFlag, *instance))
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ func IsProvisionArgs(args []string) bool {
|
||||
func RunProvision(ctx context.Context, args []string, stdout, stderr io.Writer) int {
|
||||
flags := flag.NewFlagSet(provisionCommand, flag.ContinueOnError)
|
||||
flags.SetOutput(stderr)
|
||||
flags.Usage = func() { fmt.Fprint(stderr, provisionUsage) }
|
||||
flags.Usage = func() { _, _ = fmt.Fprint(stderr, provisionUsage) }
|
||||
var options postgres.ProvisionOptions
|
||||
flags.StringVar(&options.AdminURL, "admin-url", "", "PostgreSQL URL of a role allowed to create roles and own the schema (database owner or superuser)")
|
||||
flags.StringVar(&options.RuntimeURL, "runtime-url", "", "PostgreSQL URL of the least-privilege role the services connect as")
|
||||
@@ -73,13 +73,13 @@ func RunProvision(ctx context.Context, args []string, stdout, stderr io.Writer)
|
||||
return 2
|
||||
}
|
||||
if flags.NArg() > 0 {
|
||||
fmt.Fprintf(stderr, "provision: unexpected argument %q\n", flags.Arg(0))
|
||||
_, _ = fmt.Fprintf(stderr, "provision: unexpected argument %q\n", flags.Arg(0))
|
||||
return 2
|
||||
}
|
||||
if *rotateEnv != "" {
|
||||
password, ok := os.LookupEnv(*rotateEnv)
|
||||
if !ok || password == "" {
|
||||
fmt.Fprintf(stderr, "provision: %s is unset or empty\n", *rotateEnv)
|
||||
_, _ = fmt.Fprintf(stderr, "provision: %s is unset or empty\n", *rotateEnv)
|
||||
return 2
|
||||
}
|
||||
options.NewAdminPassword = password
|
||||
@@ -87,13 +87,13 @@ func RunProvision(ctx context.Context, args []string, stdout, stderr io.Writer)
|
||||
|
||||
result, err := postgres.Provision(ctx, options)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "provision: %v\n", err)
|
||||
_, _ = fmt.Fprintf(stderr, "provision: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
if len(result.RolesCreated) > 0 {
|
||||
fmt.Fprintf(stdout, "provision: created %s\n", strings.Join(result.RolesCreated, ", "))
|
||||
_, _ = fmt.Fprintf(stdout, "provision: created %s\n", strings.Join(result.RolesCreated, ", "))
|
||||
}
|
||||
fmt.Fprintf(stdout, "provision: %s owns the schema; %s may read and write rows but not change the schema\n", result.MigrationRole, result.RuntimeRole)
|
||||
fmt.Fprintf(stdout, "provision: reconciled %d tables, %d sequences and %d functions\n", result.Tables, result.Sequences, result.Functions)
|
||||
_, _ = fmt.Fprintf(stdout, "provision: %s owns the schema; %s may read and write rows but not change the schema\n", result.MigrationRole, result.RuntimeRole)
|
||||
_, _ = fmt.Fprintf(stdout, "provision: reconciled %d tables, %d sequences and %d functions\n", result.Tables, result.Sequences, result.Functions)
|
||||
return 0
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func Run(ctx context.Context, options Options) error { //nolint:cyclop // the co
|
||||
if err != nil {
|
||||
return fmt.Errorf("listen for state store: %w", err)
|
||||
}
|
||||
defer listener.Close()
|
||||
defer func() { _ = listener.Close() }()
|
||||
b.log.InfoContext(ctx, "archie-state-store running", "addr", listener.Addr().String(), "tls", b.cfg.TLS.CertDir != "")
|
||||
|
||||
if err := b.startOptionalSurfaces(ctx, options); err != nil {
|
||||
|
||||
@@ -70,7 +70,7 @@ func TestPoolReapsOnlyOwnInstance(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cli.Close()
|
||||
defer func() { _ = cli.Close() }()
|
||||
tt.reap(&Pool{cli: cli, cfg: Config{Instance: "archie"}, log: slog.New(slog.DiscardHandler)})
|
||||
if !slices.Equal(removed, []string{"own000000000"}) {
|
||||
t.Fatalf("removed %v, want only the own instance's container", removed)
|
||||
@@ -129,7 +129,7 @@ func TestExitDetailCarriesCrashStderr(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cli.Close()
|
||||
defer func() { _ = cli.Close() }()
|
||||
p := &Pool{cli: cli, log: slog.New(slog.DiscardHandler)}
|
||||
detail := new(string)
|
||||
exited := p.watchExit(t.Context(), "crash00000000", detail)
|
||||
|
||||
@@ -98,7 +98,7 @@ func TestTaskContainerRunsOnItsOwnSandboxNetwork(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cli.Close()
|
||||
defer func() { _ = cli.Close() }()
|
||||
|
||||
sandbox := &fakeSandbox{}
|
||||
p := &Pool{
|
||||
|
||||
@@ -104,7 +104,7 @@ func readBounded(fsys fs.FS, file string) ([]byte, error) {
|
||||
}
|
||||
return nil, fmt.Errorf("open %s: %w", file, err)
|
||||
}
|
||||
defer handle.Close()
|
||||
defer func() { _ = handle.Close() }()
|
||||
|
||||
data, err := io.ReadAll(io.LimitReader(handle, maxScannedFileBytes+1))
|
||||
if err != nil {
|
||||
|
||||
@@ -211,7 +211,7 @@ func scoreAIGenerated(ctx context.Context, tc *TaskContext, meta PRMetadata) (fl
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("create intake scratch directory: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(scratch)
|
||||
defer func() { _ = os.RemoveAll(scratch) }()
|
||||
|
||||
params := json.RawMessage(`{
|
||||
"type": "object",
|
||||
|
||||
@@ -19,7 +19,7 @@ func WriteFileAtomic(path string, data []byte, mode os.FileMode) error {
|
||||
return err
|
||||
}
|
||||
tmpPath := tmp.Name()
|
||||
defer os.Remove(tmpPath) // no-op after a successful rename
|
||||
defer func() { _ = os.Remove(tmpPath) }() // no-op after a successful rename
|
||||
if err := tmp.Chmod(mode); err != nil {
|
||||
_ = tmp.Close()
|
||||
return err
|
||||
|
||||
@@ -372,24 +372,21 @@ func sessionTranscriptTool(store SessionStore, platform, channelID string) tools
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("session_transcript: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if _, err := f.Write(data); err != nil {
|
||||
_ = f.Close()
|
||||
return nil, fmt.Errorf("session_transcript: %w", err)
|
||||
}
|
||||
|
||||
stat, err := f.Stat()
|
||||
if err != nil {
|
||||
if err := f.Close(); err != nil {
|
||||
return nil, fmt.Errorf("session_transcript: %w", err)
|
||||
}
|
||||
|
||||
return sessionTranscriptResult{
|
||||
FilePath: f.Name(),
|
||||
SizeBytes: stat.Size(),
|
||||
SizeBytes: int64(len(data)),
|
||||
MessageCount: len(messages),
|
||||
SessionID: target.SessionID,
|
||||
Message: fmt.Sprintf("Transcript export written to %s (%d bytes, %d messages). Use send_file to deliver it.",
|
||||
f.Name(), stat.Size(), len(messages)),
|
||||
f.Name(), len(data), len(messages)),
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ func Serve(ctx context.Context, ln net.Listener, target string) error {
|
||||
}
|
||||
|
||||
func join(ctx context.Context, client net.Conn, target string) {
|
||||
defer client.Close()
|
||||
defer func() { _ = client.Close() }()
|
||||
upstream, err := (&net.Dialer{Timeout: dialTimeout}).DialContext(ctx, "tcp", target)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer upstream.Close()
|
||||
defer func() { _ = upstream.Close() }()
|
||||
stop := context.AfterFunc(ctx, func() {
|
||||
_ = client.Close()
|
||||
_ = upstream.Close()
|
||||
|
||||
@@ -342,7 +342,7 @@ func withHead(ctx context.Context, fetch *http.Client, m messaging.MediaAttachme
|
||||
if err != nil {
|
||||
return m, fmt.Errorf("%s attachment URL is unreadable: %w", m.Type, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
|
||||
return m, fmt.Errorf("%s attachment URL answered %s", m.Type, resp.Status)
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ func fetch(ctx context.Context, opts Options) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fetch model catalog: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("fetch model catalog: status %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestTaskSandboxEndsWithItsTask(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
client := fake.NewClient()
|
||||
defer client.Close()
|
||||
defer func() { _ = client.Close() }()
|
||||
rt := New(client, Options{Instance: "archie", Poll: 5 * time.Millisecond, MaxUptime: func() time.Duration { return tt.maxUptime }})
|
||||
|
||||
sb, err := rt.Acquire(t.Context(), Launch{Image: "agent:test", Worker: egress.Endpoints{NATS: "nats://nats.example.internal:4222"}})
|
||||
@@ -79,7 +79,7 @@ func TestTaskSandboxEndsWithItsTask(t *testing.T) {
|
||||
// instance's or ones archie did not create.
|
||||
func TestSweepRemovesOnlyThisInstancesSandboxes(t *testing.T) {
|
||||
client := fake.NewClient()
|
||||
defer client.Close()
|
||||
defer func() { _ = client.Close() }()
|
||||
for name, labels := range map[string]map[string]string{
|
||||
"archie-agent-1": {instanceLabel: "archie"},
|
||||
"staging-agent-1": {instanceLabel: "staging"},
|
||||
|
||||
@@ -19,7 +19,7 @@ func extractTarGz(r io.Reader, destDir string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("prsource: open archive: %w", err)
|
||||
}
|
||||
defer gz.Close()
|
||||
defer func() { _ = gz.Close() }()
|
||||
|
||||
dest, err := filepath.Abs(destDir)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package prsource
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -104,7 +105,7 @@ func copyTree(src, dst string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func copyFile(src, dst string) error {
|
||||
func copyFile(src, dst string) (err error) {
|
||||
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -112,12 +113,12 @@ func copyFile(src, dst string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
defer func() { _ = in.Close() }()
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
defer func() { err = errors.Join(err, out.Close()) }()
|
||||
_, err = io.Copy(out, in)
|
||||
return err
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func (s *Source) Snapshot(ctx context.Context, owner, repo string, number int, d
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("prsource: fetch repository archive at %s: %w", pr.HeadSHA, err)
|
||||
}
|
||||
defer archive.Close()
|
||||
defer func() { _ = archive.Close() }()
|
||||
if err := extractTarGz(archive, destDir); err != nil {
|
||||
return "", fmt.Errorf("prsource: extract repository archive: %w", err)
|
||||
}
|
||||
|
||||
@@ -93,18 +93,18 @@ func (t *Terminal) readSecretLine(ctx context.Context) (string, error) {
|
||||
// Select presents options and returns the chosen index.
|
||||
func (t *Terminal) Select(ctx context.Context, prompt string, options []string) (int, error) {
|
||||
for {
|
||||
fmt.Fprintln(t.out, prompt)
|
||||
_, _ = fmt.Fprintln(t.out, prompt)
|
||||
for i, opt := range options {
|
||||
fmt.Fprintf(t.out, " %d) %s\n", i+1, opt)
|
||||
_, _ = fmt.Fprintf(t.out, " %d) %s\n", i+1, opt)
|
||||
}
|
||||
fmt.Fprintf(t.out, "Select [1-%d]: ", len(options))
|
||||
_, _ = fmt.Fprintf(t.out, "Select [1-%d]: ", len(options))
|
||||
line, err := t.readLine(ctx)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
n, convErr := strconv.Atoi(strings.TrimSpace(line))
|
||||
if convErr != nil || n < 1 || n > len(options) {
|
||||
fmt.Fprintf(t.out, "Please enter a number between 1 and %d.\n", len(options))
|
||||
_, _ = fmt.Fprintf(t.out, "Please enter a number between 1 and %d.\n", len(options))
|
||||
continue
|
||||
}
|
||||
return n - 1, nil
|
||||
@@ -114,7 +114,7 @@ func (t *Terminal) Select(ctx context.Context, prompt string, options []string)
|
||||
// ReadLine reads one line of visible input, falling back to defaultValue
|
||||
// when the answer is empty.
|
||||
func (t *Terminal) ReadLine(ctx context.Context, prompt, defaultValue string) (string, error) {
|
||||
fmt.Fprint(t.out, prompt)
|
||||
_, _ = fmt.Fprint(t.out, prompt)
|
||||
line, err := t.readLine(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -127,9 +127,9 @@ func (t *Terminal) ReadLine(ctx context.Context, prompt, defaultValue string) (s
|
||||
|
||||
// ReadSecret reads one line of input without echoing it.
|
||||
func (t *Terminal) ReadSecret(ctx context.Context, prompt string) (string, error) {
|
||||
fmt.Fprint(t.out, prompt)
|
||||
_, _ = fmt.Fprint(t.out, prompt)
|
||||
line, err := t.readSecretLine(ctx)
|
||||
fmt.Fprintln(t.out)
|
||||
_, _ = fmt.Fprintln(t.out)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func (t *Terminal) Confirm(ctx context.Context, prompt string, defaultYes bool)
|
||||
if defaultYes {
|
||||
suffix = "[Y/n]"
|
||||
}
|
||||
fmt.Fprintf(t.out, "%s %s: ", prompt, suffix)
|
||||
_, _ = fmt.Fprintf(t.out, "%s %s: ", prompt, suffix)
|
||||
line, err := t.readLine(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
@@ -91,7 +91,7 @@ func ReadJSONLines[T any](path string, fn func(T) error) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("open JSONL file: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
scanner.Buffer(make([]byte, 64*1024), 8*1024*1024)
|
||||
|
||||
@@ -14,11 +14,15 @@ func writeSpillFile(dir, toolName string, content []byte) string {
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
defer f.Close()
|
||||
if err := f.Chmod(0o600); err != nil {
|
||||
_ = f.Close()
|
||||
return ""
|
||||
}
|
||||
if _, err := f.Write(content); err != nil {
|
||||
_ = f.Close()
|
||||
return ""
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
return ""
|
||||
}
|
||||
return f.Name()
|
||||
|
||||
@@ -244,8 +244,12 @@ func saveFullOutput(output string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.WriteString(output); err != nil {
|
||||
_ = f.Close()
|
||||
_ = os.Remove(f.Name())
|
||||
return "", err
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
_ = os.Remove(f.Name())
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func (c *Client) Fetch(ctx context.Context, rawURL string, raw bool) (string, er
|
||||
if err != nil {
|
||||
return "", unwrapFetchError(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
body, truncated, err := c.readBody(resp)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user