use exit code to signify recall errors

instead of just assuming empty response means error
pull/58/head
Simon Let 6 years ago
parent 93b7c07174
commit 4dfe16321b
  1. 2
      Makefile
  2. 6
      cmd/collect/main.go
  3. 8
      cmd/daemon/recall.go
  4. 5
      pkg/collect/collect.go
  5. 2
      scripts/hooks.sh
  6. 6
      scripts/widgets.sh

@ -1,7 +1,7 @@
SHELL=/bin/bash
LATEST_TAG=$(shell git describe --tags)
REVISION=$(shell [ -z "$(git status --untracked-files=no --porcelain)" ] && git rev-parse --short=12 HEAD || echo "no_revision")
VERSION=${LATEST_TAG}-dev-${REVISION}
VERSION="${LATEST_TAG}-DEV"
GOFLAGS=-ldflags "-X main.version=${VERSION} -X main.commit=${REVISION}"
sanitize:

@ -175,7 +175,11 @@ func main() {
RecallHistno: *recallHistno,
RecallPrefix: *recallPrefix,
}
fmt.Print(collect.SendRecallRequest(rec, strconv.Itoa(config.Port)))
str, found := collect.SendRecallRequest(rec, strconv.Itoa(config.Port))
if found == false {
os.Exit(1)
}
fmt.Println(str)
} else {
rec := records.Record{
// posix

@ -34,13 +34,15 @@ func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
log.Println("/recall recalling ...")
found := true
cmd, err := h.sesshistDispatch.Recall(rec.SessionID, rec.RecallHistno, rec.RecallPrefix)
if err != nil {
log.Println("/recall - sess id:", rec.SessionID, " - histno:", rec.RecallHistno, " -> ERROR")
log.Println("Recall error:", err)
return
found = false
cmd = ""
}
resp := collect.SingleResponse{CmdLine: cmd}
resp := collect.SingleResponse{CmdLine: cmd, Found: found}
log.Println("/recall marshaling response ...")
jsn, err = json.Marshal(&resp)
if err != nil {
@ -51,7 +53,7 @@ func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println(string(jsn))
log.Println("/recall writing response ...")
w.Write(jsn)
log.Println("/recall END - sess id:", rec.SessionID, " - histno:", rec.RecallHistno, " -> ", cmd)
log.Println("/recall END - sess id:", rec.SessionID, " - histno:", rec.RecallHistno, " -> ", cmd, " (found:", found, ")")
}
type inspectHandler struct {

@ -15,11 +15,12 @@ import (
// SingleResponse json struct
type SingleResponse struct {
Found bool `json:"found"`
CmdLine string `json:"cmdline"`
}
// SendRecallRequest to daemon
func SendRecallRequest(r records.SlimRecord, port string) string {
func SendRecallRequest(r records.SlimRecord, port string) (string, bool) {
recJSON, err := json.Marshal(r)
if err != nil {
log.Fatal("send err 1", err)
@ -50,7 +51,7 @@ func SendRecallRequest(r records.SlimRecord, port string) string {
log.Fatal("unmarshal resp error: ", err)
}
log.Println(response)
return response.CmdLine
return response.CmdLine, response.Found
}
// SendRecord to daemon

@ -103,7 +103,9 @@ __resh_collect() {
-osReleasePrettyName "$__RESH_OS_RELEASE_PRETTY_NAME" \
-histno "$__RESH_HISTNO" \
"$@"
return $?
fi
return 1
}
__resh_precmd() {

@ -51,10 +51,12 @@ __resh_widget_arrow_up() {
else
# run recall
local NEW_BUFFER
local status_code
NEW_BUFFER="$(__resh_collect --recall --prefix-search "$__RESH_PREFIX" 2> ~/.resh/arrow_up_last_run_out.txt)"
# IF new buffer in non-empty THEN use the new buffer ELSE revert histno change
status_code=$?
# revert histno change on error
# shellcheck disable=SC2015
if [ "${#NEW_BUFFER}" -gt 0 ]; then
if [ "${status_code}" -eq 0 ]; then
BUFFER=$NEW_BUFFER
else
__RESH_HISTNO=$((__RESH_HISTNO-1))

Loading…
Cancel
Save