Skip to content

Commit

Permalink
improve errors
Browse files Browse the repository at this point in the history
  • Loading branch information
4e554c4c committed Oct 8, 2023
1 parent ca2b3b3 commit 150aa63
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/4e554c4c/darkman.nvim
go 1.19

require (
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/neovim/go-client v1.2.1 // indirect
github.com/godbus/dbus/v5 v5.1.0
github.com/neovim/go-client v1.2.1
)
43 changes: 21 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,40 @@ func (args *setupArgs) handleNewMode() error {
}

func setup(v *nvim.Nvim, args setupArgs) {
var err error
var p Portal
var ch <-chan uint32
if currentMode != UNINITIALIZED {
v.WriteErr("darkman: setup() already called")
err = errors.New("setup() already called")
goto error
}
args.v = v
p, err := setupPortal()
if err != nil {
v.WriteErr(fmt.Sprintf("darkman: %v", err))
return
if p, err = setupPortal(); err != nil {
goto error
}
currentMode, err = p.getMode()
if err != nil {
v.WriteErr(fmt.Sprintf("darkman: %v", err))
return
if currentMode, err = p.getMode(); err != nil {
goto error
}
err = args.handleNewMode()
if err != nil {
v.WriteErr(fmt.Sprintf("darkman: %v", err))
return
if err = args.handleNewMode(); err != nil {
goto error
}

ch, err := p.setupSignal()
if err != nil {
v.WriteErr(fmt.Sprintf("darkman: %v", err))
return
if ch, err = p.setupSignal(); err != nil {
goto error
}
go func() {
for {
newMode := <-ch
if newMode == currentMode {
continue
if newMode := <-ch; newMode != currentMode {
currentMode = newMode
args.handleNewMode()
}
currentMode = newMode
args.handleNewMode()
}
}()
return

error:
v.WriteErr(fmt.Sprintf("darkman: %v\n", err))
return
}

func main() {
Expand Down

0 comments on commit 150aa63

Please sign in to comment.