Skip to content

Commit

Permalink
chore: work on making errors more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
distek committed Feb 21, 2024
1 parent 61c42d4 commit ae061e8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
7 changes: 4 additions & 3 deletions cmd/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var cleanCmd = &cobra.Command{

o, e, err := lib.Tmux(lib.GlobalArgs, "ls", nil, "")
if err != nil {
log.Printf("Got err: %s: %s", err, e)
os.Exit(1)
log.Println(e)
log.Fatal(err)
}

for _, v := range strings.Split(o, "\n") {
Expand All @@ -32,7 +32,8 @@ var cleanCmd = &cobra.Command{

_, e, err := lib.Tmux(lib.GlobalArgs, "kill-window", map[string]string{"-t": id}, "")
if err != nil {
log.Printf("Got err: %s: %s", err, e)
log.Println(e)
log.Fatal(err)
return
}
}
Expand Down
11 changes: 8 additions & 3 deletions cmd/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ var sessionSaveCmd = &cobra.Command{
"-F": sessionWinLinesFmt,
}, "")
if err != nil {
log.Fatalf("got err: err=%s, out=%s", err, e)
log.Println(e)
log.Fatal(err)
}

var session Session
Expand Down Expand Up @@ -106,7 +107,8 @@ var sessionSaveCmd = &cobra.Command{
"-F": sessionPaneLinesFmt,
}, "")
if err != nil {
log.Fatalf("got err: err=%s, out=%s", err, e)
log.Println(e)
log.Fatal(err)
}

for _, p := range strings.Split(paneLines, "\n") {
Expand Down Expand Up @@ -165,7 +167,10 @@ var sessionSaveCmd = &cobra.Command{
log.Fatal(err)
}

err = os.WriteFile(xdg.ConfigHome+"/tmux/sessions/"+flagSessionName+".json", s, 0640)
err = os.WriteFile(
xdg.ConfigHome+"/tmux/sessions/"+flagSessionName+".json",
s,
0640)
if err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/wm.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ func splitFull(pane lib.Pane, dir string) {

merged := mergeMaps(defaultArgs, extraArgs)

o, e, err := lib.Tmux(lib.GlobalArgs, "split-window", merged, "cat")
_, e, err := lib.Tmux(lib.GlobalArgs, "split-window", merged, "cat")
if err != nil {
log.Fatal(fmt.Errorf("cmd: moveWindowInDir: lib.Tmux: up: command failed: err=%s, stdout=%s, err=%s", err, o, e))
log.Println(e)
log.Fatal(err)
}

newPane, err := lib.GetCurrentPane()
Expand Down
44 changes: 25 additions & 19 deletions lib/pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,20 @@ func GetCurrentPane() (Pane, error) {
}, "")

if err != nil {
return Pane{}, fmt.Errorf("lib: getPaneInDir: Tmux: command failed: err=%s, stdout=%s, stderr=%s", err, o, e)
log.Println(e)
return Pane{}, err
}

return parsePaneLine(strings.Split(o, "\n")[0])
}

func SelectPane(pane Pane) error {
o, e, err := Tmux(GlobalArgs, "select-pane", map[string]string{
_, e, err := Tmux(GlobalArgs, "select-pane", map[string]string{
"-t": pane.ID,
}, "")
if err != nil {
return fmt.Errorf("lib: selectPane: Tmux: command failed: err=%s, stdout=%s, stderr=%s", err, o, e)
log.Println(e)
return err
}

return nil
Expand Down Expand Up @@ -213,14 +215,14 @@ var dirArgs = map[string][]string{
}

// GetFurthestPaneInDir - valid args are:
// top-left
// top-right
// bottom-left
// bottom-right
// left
// right
// up
// down
// top-left,
// top-right,
// bottom-left,
// bottom-right,
// left,
// right,
// up,
// and down
func GetFurthestPaneInDir(dir string) (Pane, error) {
panes, err := GetPanes()
if err != nil {
Expand All @@ -238,7 +240,8 @@ func GetFurthestPaneInDir(dir string) (Pane, error) {
"-F": dirArgs[dir][0],
}, "")
if err != nil {
return Pane{}, fmt.Errorf("lib: GetFurthestPaneInDir: Tmux: command failed: err=%s, stdout=%s, stderr=%s", err, o, e)
log.Println(e)
return Pane{}, err
}

o = strings.Split(o, "\n")[0]
Expand All @@ -248,7 +251,7 @@ func GetFurthestPaneInDir(dir string) (Pane, error) {
}
}

return Pane{}, fmt.Errorf("lib: GetFurthestPaneInDir: could not find furthest %s pane?", dir)
return Pane{}, fmt.Errorf("could not find furthest %s pane?", dir)
}

type Neighbor struct {
Expand Down Expand Up @@ -281,7 +284,7 @@ func GetNeighbors(pane Pane) (Neighbors, error) {

p, ok, err := GetPaneInDir(pane, k)
if err != nil {
return Neighbors{}, fmt.Errorf("lib: GetNeighbors: GetPaneInDir: %s : %s", k, err)
return Neighbors{}, fmt.Errorf("%s : %s", k, err)
}

ret.Panes[k] = Neighbor{
Expand All @@ -305,22 +308,24 @@ func GetPanesLen() int {
}

func KillPane(pane Pane) error {
o, e, err := Tmux(GlobalArgs, "kill-pane", map[string]string{
_, e, err := Tmux(GlobalArgs, "kill-pane", map[string]string{
"-t": pane.ID,
}, "")
if err != nil {
return fmt.Errorf("lib: KillPane: Tmux: command failed: err=%s, stdout=%s, stderr=%s", err, o, e)
log.Println(e)
return err
}

return nil
}

func FocusPane(pane Pane) error {
o, e, err := Tmux(GlobalArgs, "select-pane", map[string]string{
_, e, err := Tmux(GlobalArgs, "select-pane", map[string]string{
"-t": pane.ID,
}, "")
if err != nil {
return fmt.Errorf("lib: KillPane: Tmux: command failed: err=%s, stdout=%s, stderr=%s", err, o, e)
log.Println(e)
return err
}

return nil
Expand All @@ -333,7 +338,8 @@ func IsVim(pane Pane) bool {
"-p": "\"#{pane_current_command}\"",
}, "")
if err != nil {
log.Printf("err occurred: err=%s output=%s", err, e)
log.Println(e)
log.Println(err)
return false
}

Expand Down

0 comments on commit ae061e8

Please sign in to comment.