Skip to content

Commit

Permalink
Merge pull request #151 from imsodin/panicKqueue
Browse files Browse the repository at this point in the history
kqueue: Don't panic when an error occurs on init (fixes #149)
  • Loading branch information
rjeczalik committed Jun 24, 2018
2 parents 808e64c + db81c87 commit f7ce7f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
15 changes: 15 additions & 0 deletions watcher_notimplemented.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2014-2018 The Notify Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

// +build !darwin,!linux,!freebsd,!dragonfly,!netbsd,!openbsd,!windows
// +build !kqueue,!solaris

package notify

import "errors"

// newWatcher stub.
func newWatcher(chan<- EventInfo) watcher {
return watcherStub{errors.New("notify: not implemented")}
}
22 changes: 6 additions & 16 deletions watcher_stub.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
// Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
// Copyright (c) 2014-2018 The Notify Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

// +build !darwin,!linux,!freebsd,!dragonfly,!netbsd,!openbsd,!windows
// +build !kqueue,!solaris

package notify

import "errors"

type stub struct{ error }

// newWatcher stub.
func newWatcher(chan<- EventInfo) watcher {
return stub{errors.New("notify: not implemented")}
}
type watcherStub struct{ error }

// Following methods implement notify.watcher interface.
func (s stub) Watch(string, Event) error { return s }
func (s stub) Rewatch(string, Event, Event) error { return s }
func (s stub) Unwatch(string) (err error) { return s }
func (s stub) Close() error { return s }
func (s watcherStub) Watch(string, Event) error { return s }
func (s watcherStub) Rewatch(string, Event, Event) error { return s }
func (s watcherStub) Unwatch(string) (err error) { return s }
func (s watcherStub) Close() error { return s }
3 changes: 2 additions & 1 deletion watcher_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func newWatcher(c chan<- EventInfo) watcher {
}
t.t = newTrigger(t.pthLkp)
if err := t.t.Init(); err != nil {
panic(err)
t.Close()
return watcherStub{fmt.Errorf("failed setting up watcher: %v", err)}
}
go t.monitor()
return t
Expand Down

0 comments on commit f7ce7f7

Please sign in to comment.