fix: use errors.Is/As for context errors and cleanup

This commit is contained in:
sam committed 2026-07-30 00:06:10 +10:00
1 parent 35213e09b0
commit 6108fc5548
10 files changed
+17 -8

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@ func parseModelRest(rest string) (model, provider string, global, session, refre
}
}
model = strings.Join(modelParts, " ")
return
return model, provider, global, session, refresh
}
// extractProviderFlag extracts --provider=<value> or --provider <value>
@@ -26,7 +26,7 @@ type fileSet struct {
// main returns the daemon-level config file and its format. YAML wins when
// both are present; legacy config.toml is the fallback.
func (fs fileSet) main() (path string, yaml bool, ok bool) {
func (fs fileSet) main() (path string, yaml, ok bool) {
if fs.mainYAML != "" {
return fs.mainYAML, true, true
}
@@ -342,6 +342,7 @@ func TestFinalizeIndexingDefaults(t *testing.T) {
})
}
}
func TestIdentitiesConfigParsesTwoIdentities(t *testing.T) {
cfg, err := loadBytes([]byte(`
bot_user = "default-legacy"
@@ -38,6 +38,7 @@ func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Name() stri
}
return W.WName()
}
func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Version() string {
if W.WVersion == nil {
return ""
@@ -41,12 +41,14 @@ func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Name() stri
}
return W.WName()
}
func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Resolve(key string) (string, error) {
if W.WResolve == nil {
return "", nil
}
return W.WResolve(key)
}
func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Version() string {
if W.WVersion == nil {
return ""
+2 -1
View File
@@ -13,6 +13,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
@@ -238,7 +239,7 @@ func runFindGoFallback(ctx context.Context, cwd, searchPath string, p FindParams
return nil
})
if err != nil && err != ctx.Err() {
if err != nil && !errors.Is(err, ctx.Err()) {
return Result{Content: fmt.Sprintf("find error: %v", err), IsError: true}, nil
}
+4 -2
View File
@@ -13,6 +13,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
@@ -211,7 +212,8 @@ func makeGrepExecutor(cwd string, workspaceIndex GrepIndex) Executor {
output = stdout.String()
}
if output == "" && err != nil {
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 1 {
exitErr := &exec.ExitError{}
if errors.As(err, &exitErr) {
return grepBackendResult(Result{Content: "no matches found"}, searchBackend, clamped), nil
}
errMsg := stderr.String()
@@ -413,7 +415,7 @@ func grepFallback(ctx context.Context, p GrepParams, searchPath, cwd string, tar
results = append(results, res...)
return nil
})
if err != nil && err != ctx.Err() {
if err != nil && !errors.Is(err, ctx.Err()) {
return "", err
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"testing"
)
func execRead(t *testing.T, cwd string, params string) Result {
func execRead(t *testing.T, cwd, params string) Result {
t.Helper()
tool := NewReadTool(cwd, nil)
res, err := tool.Execute(context.Background(), json.RawMessage(params), nil)
+3 -1
View File
@@ -20,6 +20,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
@@ -192,7 +193,8 @@ func makeShellExecutor(cwd string, mq *MutationQueue) Executor {
}, nil
}
if exitErr, ok := err.(*exec.ExitError); ok {
exitErr := &exec.ExitError{}
if errors.As(err, &exitErr) {
return Result{
Content: fmt.Sprintf("[exit code: %d]\n%s", exitErr.ExitCode(), content), IsError: true,
ErrorKind: "command_exit", Truncated: tr.Truncated, ResultBytes: len(output),
+1 -1
View File
@@ -302,7 +302,7 @@ func TestHandleSSEEventsSinceError(t *testing.T) {
ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", ts.URL+"/events?since=0", nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/events?since=0", nil)
if err != nil {
t.Fatal(err)
}