Skip to content

Commit

Permalink
Add error checking if the store fails
Browse files Browse the repository at this point in the history
  • Loading branch information
joelim-work committed Jun 20, 2023
1 parent 4c907d9 commit c55607a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
25 changes: 19 additions & 6 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,21 @@ func (app *app) loop() {
}
}

func (app *app) exportData() {
store("maps", listBinds(gOpts.keys))
store("cmaps", listBinds(gOpts.cmdkeys))
store("cmds", listCmds())
store("jumps", listJumps(app.nav.jumpList, app.nav.jumpListInd))
func (app *app) exportData() error {
if err := store("maps", listBinds(gOpts.keys)); err != nil {
return err
}
if err := store("cmaps", listBinds(gOpts.cmdkeys)); err != nil {
return err
}
if err := store("cmds", listCmds()); err != nil {
return err
}
if err := store("jumps", listJumps(app.nav.jumpList, app.nav.jumpListInd)); err != nil {
return err
}

return nil
}

func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
Expand Down Expand Up @@ -520,7 +530,10 @@ func (app *app) runShell(s string, args []string, prefix string) {
exportOpts()

if !gSingleMode {
app.exportData()
if err := app.exportData(); err != nil {
app.ui.echoerrf("exporting data: %s", err)
return
}
}

cmd := shellCommand(s, args)
Expand Down
12 changes: 8 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ func remote(cmd string) error {
return nil
}

func store(key string, reader io.Reader) {
func store(key string, reader io.Reader) error {
c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil {
log.Printf("dialing to send server: %s", err)
return
return fmt.Errorf("dialing to send server: %s", err)
}
defer c.Close()

Expand All @@ -145,5 +144,10 @@ func store(key string, reader io.Reader) {
}

// wait for server to finish storing data and send response, if any
io.ReadAll(c)
_, err = io.ReadAll(c)
if err != nil {
return fmt.Errorf("getting response from server: %s", err)
}

return nil
}

0 comments on commit c55607a

Please sign in to comment.