fix: use errors.Is/As for context errors and cleanup
This commit is contained in:
1 parent
35213e09b0
commit
6108fc5548
10 files changed
+17
-8
No files matched your search
@@ -57,7 +57,7 @@ func parseModelRest(rest string) (model, provider string, global, session, refre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
model = strings.Join(modelParts, " ")
|
model = strings.Join(modelParts, " ")
|
||||||
return
|
return model, provider, global, session, refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractProviderFlag extracts --provider=<value> or --provider <value>
|
// 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
|
// main returns the daemon-level config file and its format. YAML wins when
|
||||||
// both are present; legacy config.toml is the fallback.
|
// 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 != "" {
|
if fs.mainYAML != "" {
|
||||||
return fs.mainYAML, true, true
|
return fs.mainYAML, true, true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,6 +342,7 @@ func TestFinalizeIndexingDefaults(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIdentitiesConfigParsesTwoIdentities(t *testing.T) {
|
func TestIdentitiesConfigParsesTwoIdentities(t *testing.T) {
|
||||||
cfg, err := loadBytes([]byte(`
|
cfg, err := loadBytes([]byte(`
|
||||||
bot_user = "default-legacy"
|
bot_user = "default-legacy"
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Name() stri
|
|||||||
}
|
}
|
||||||
return W.WName()
|
return W.WName()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Version() string {
|
func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Version() string {
|
||||||
if W.WVersion == nil {
|
if W.WVersion == nil {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -41,12 +41,14 @@ func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Name() stri
|
|||||||
}
|
}
|
||||||
return W.WName()
|
return W.WName()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Resolve(key string) (string, error) {
|
func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Resolve(key string) (string, error) {
|
||||||
if W.WResolve == nil {
|
if W.WResolve == nil {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
return W.WResolve(key)
|
return W.WResolve(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Version() string {
|
func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Version() string {
|
||||||
if W.WVersion == nil {
|
if W.WVersion == nil {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -238,7 +239,7 @@ func runFindGoFallback(ctx context.Context, cwd, searchPath string, p FindParams
|
|||||||
return nil
|
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
|
return Result{Content: fmt.Sprintf("find error: %v", err), IsError: true}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -211,7 +212,8 @@ func makeGrepExecutor(cwd string, workspaceIndex GrepIndex) Executor {
|
|||||||
output = stdout.String()
|
output = stdout.String()
|
||||||
}
|
}
|
||||||
if output == "" && err != nil {
|
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
|
return grepBackendResult(Result{Content: "no matches found"}, searchBackend, clamped), nil
|
||||||
}
|
}
|
||||||
errMsg := stderr.String()
|
errMsg := stderr.String()
|
||||||
@@ -413,7 +415,7 @@ func grepFallback(ctx context.Context, p GrepParams, searchPath, cwd string, tar
|
|||||||
results = append(results, res...)
|
results = append(results, res...)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil && err != ctx.Err() {
|
if err != nil && !errors.Is(err, ctx.Err()) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func execRead(t *testing.T, cwd string, params string) Result {
|
func execRead(t *testing.T, cwd, params string) Result {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
tool := NewReadTool(cwd, nil)
|
tool := NewReadTool(cwd, nil)
|
||||||
res, err := tool.Execute(context.Background(), json.RawMessage(params), nil)
|
res, err := tool.Execute(context.Background(), json.RawMessage(params), nil)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -192,7 +193,8 @@ func makeShellExecutor(cwd string, mq *MutationQueue) Executor {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
exitErr := &exec.ExitError{}
|
||||||
|
if errors.As(err, &exitErr) {
|
||||||
return Result{
|
return Result{
|
||||||
Content: fmt.Sprintf("[exit code: %d]\n%s", exitErr.ExitCode(), content), IsError: true,
|
Content: fmt.Sprintf("[exit code: %d]\n%s", exitErr.ExitCode(), content), IsError: true,
|
||||||
ErrorKind: "command_exit", Truncated: tr.Truncated, ResultBytes: len(output),
|
ErrorKind: "command_exit", Truncated: tr.Truncated, ResultBytes: len(output),
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ func TestHandleSSEEventsSinceError(t *testing.T) {
|
|||||||
ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second)
|
||||||
defer cancel()
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user