GithubHelp home page GithubHelp logo

Error handling about notify HOT 13 CLOSED

rjeczalik avatar rjeczalik commented on June 11, 2024
Error handling

from notify.

Comments (13)

rjeczalik avatar rjeczalik commented on June 11, 2024
  1. notify.Error
const (
  Create = Event(...)
  Delete = Event(...)
  ...
  Error   = Event(...)
)
notify.Watch("/home/pknap/rottenbodies", ch, notify.Delete, notify.Error)
for ei := range ch {
  switch ei.Event() {
  case notify.Delete:
    println("the bodies are gone")
  case notify.Error:
    println("they're alive:", ei.Sys().(error))
  }
}
  • notify.Watch("/path", ch) listens notify.Error by default as well
  • not listening to a notify.Error means it's ignored

It's guaranteed that:

  • a notify.Error is followed by a chan close
  • when Event() == notify.Error, it's safe to err := ei.Sys().(error)

Plus is minimalistic API. Cons is Error is not an event... oh wait, it is. XD

Other than that I like 1).

from notify.

ppknap avatar ppknap commented on June 11, 2024

How about an implicit notify.Error event:

notify.Watch("/home/pknap/rottenbodies", ch, notify.Delete)
for ei := range ch {
  switch ei.Event() {
  case notify.Delete:
    println("the bodies are gone")
  case notify.Error:
    println("they're alive:", ei.Sys().(error))
  }
}

I`ve updated option no.1 and I like it too.

from notify.

rjeczalik avatar rjeczalik commented on June 11, 2024

It should be possible to say: Watch this and I don't care about the error, just close the chan. Because receiving notify.Error and not reading Sys().(error) gives the same information as !ok received by the chan close.

from notify.

ppknap avatar ppknap commented on June 11, 2024

In the other hand, how long should we keep the ch<-->error pair. Since the user may want to always call notify.Error(ch) on deleted channel?

from notify.

rjeczalik avatar rjeczalik commented on June 11, 2024

Yup, the problem with 1) is the lifetime of underlying map[chan<- notify]error. No idea how to deal with that. That's why I would pick 3), as eventually deleting notify.Error and introducing something else is relatively simple.

from notify.

ppknap avatar ppknap commented on June 11, 2024

Ok in this case we send ch <- zjebalosie{err: err} and then close the channel ?

from notify.

rjeczalik avatar rjeczalik commented on June 11, 2024

If zjebalosie implements EventInfo it's cool.

from notify.

ppknap avatar ppknap commented on June 11, 2024

👍

from notify.

rjeczalik avatar rjeczalik commented on June 11, 2024
  • notify.Error is implicit, meaning the ch after following Watch may receive an error
notify.Watch("/path", ch, notify.Create)
  • in order to ignore receiving an error user may want to use ^notify.Error:
notify.Watch("/path", ch, notify.Create, ^notify.Error)

(obviously this wouldn't work with short event declaration, like: notify.Create | ^notify.Error, only long one is supported)

from notify.

ppknap avatar ppknap commented on June 11, 2024

eg:

notify.Create == Event(0x1) // 0001b
notify.Delete == Event(0x2) // 0010b
notify.Move  == Event(0x4) // 0100b
notify.Error == Event(0x8)  // 1000b
...
notify.Create | notify.Delete | notify.Move == ^notify.Error 
.... => // the only fix?:
notify.Error == notify.Create | notify.Delete | notify.Move
...

Is it possible to implement this logic correctly?

[edit]

Hmm hopefully it is, but notify.Error needs to reserve 2 bits 👍

from notify.

ppknap avatar ppknap commented on June 11, 2024

If it has two bits reserved also your notify.Create | ^notify.Error will be possible:

notify.Create == Event(0x1) // 00001b
notify.Delete == Event(0x2) // 00010b
notify.Move  == Event(0x4) // 00100b
notify.Error == Event(0x8)  // 01000b , bit 4th ant 5th are reserved 

bit 4th == 0, bit 5th == 0 => implicit error
bit 4th == 1, bit 5th == 0 => explicit notify.Error was passed as an argument
bit 4th == 0, bit 5th == 1 => explicit ^notify.Error was passed
bit 4th == 1, bit 5th == 1 => somebody tries to cheat us

[edit]
bit 4th == 1, bit 5th == 1 => notify.Error | ^notify.Error => no-op <=> bit 4th == 0, bit 5th == 0

from notify.

ppknap avatar ppknap commented on June 11, 2024
  • taken from os/signal Notify causes package signal to relay incoming signals to c. If no signals are listed, all incoming signals will be relayed to c. Otherwise, just the listed signals will. thus:
notify.Watch("dupa", ch) == notify.Watch("dupa", ch, notify.Create, notify.Delete, notify.Move, notify.Error, notify.Write) // but not system-dependent events.

;>

from notify.

ppknap avatar ppknap commented on June 11, 2024

and if we have the notify.Error event I would rather not close the channel on error.

  • no need to write creepy logic which is responsible for storing errors.
  • I can recover the reading loop after error occures (inotify/ReadDirectoryChanges)
  • os/signal has no such logic
  • the code will panic if someone receives nil EventInfo from closed channel and invokes ei.Event()

from notify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.