the unplaceable word rides a typed error, not the message (V-634)
Recovering it by cutting on quotes in err.Error() meant the reply depended on the wording of an error string. UnknownTargetError carries the word and errors.Is still holds.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/kami/maven/internal/mcp"
|
||||
"github.com/kami/maven/internal/phraser"
|
||||
@@ -66,8 +65,12 @@ func (h *reactiveHandler) actionAct(ctx context.Context, dec router.Decision) st
|
||||
// nothing ran. Saying which word she could not place is the whole
|
||||
// answer: he either renames it or gives the row an alias that
|
||||
// carries the target, and both are one turn away (V-634).
|
||||
return phraser.A(phraser.ActUnknownTarget,
|
||||
map[string]string{"name": unknownTargetOf(err, dec.Slots.Args)})
|
||||
word := ""
|
||||
var unknown *tool.UnknownTargetError
|
||||
if errors.As(err, &unknown) {
|
||||
word = unknown.Target
|
||||
}
|
||||
return phraser.A(phraser.ActUnknownTarget, map[string]string{"name": word})
|
||||
case errors.Is(err, tool.ErrNeedsAuthedSurface):
|
||||
// Irreversible (internal/tool/risk.go). A confirm turn would not
|
||||
// help: everything that proposed this act — the STT, the router,
|
||||
@@ -102,17 +105,3 @@ func (h *reactiveHandler) actionAct(ctx context.Context, dec router.Decision) st
|
||||
return phraser.A(phraser.ActDone, nil)
|
||||
}
|
||||
|
||||
// unknownTargetOf pulls the word the executor could not place out of its error,
|
||||
// falling back to the first arg. The word is what makes the reply usable, and a
|
||||
// reply naming no word would send him to the log.
|
||||
func unknownTargetOf(err error, args []string) string {
|
||||
if _, rest, ok := strings.Cut(err.Error(), `"`); ok {
|
||||
if word, _, ok := strings.Cut(rest, `"`); ok && word != "" {
|
||||
return word
|
||||
}
|
||||
}
|
||||
if len(args) > 0 {
|
||||
return args[0]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user