hi, Just wondering if one has considered to handle certain errors in such way, why / why not
https://play.golang.org/p/Pc8Pv7d6eK I came to do an err struct like this, //SmartErr ... type SmartErr struct { error IsFatal bool IsEOA bool // End of application } //NewSmartErr ... func NewSmartErr(m string) *SmartErr { return &SmartErr{error: errors.New(m)} } //Fatal ... func (e *SmartErr) Fatal() *SmartErr { e.IsFatal = true; return e } //EOA ... func (e *SmartErr) EOA() *SmartErr { e.IsEOA = true; return e } Then i put a test like this in the main, for e := range errRecv { if e != nil { if s, ok := e.(*SmartErr); ok { if s.IsEOA { break } if s.IsFatal { log.Fatal(e) } else { log.Println(e) } } else { log.Fatal(e) } } } EOA is kind of specific to this use case, it s inspired by io.EOF. But the idea is to flag an error be fatal or not, End Of Application or not, EOF..., and that this could be configured at runtime while the caller stack is returning. So one component might return an error and say that this one is fatal, or not that much. Also, if a parent receives an error (no matter of its type), it might implement a recover handler, so the application can continue, in that case, t might also decide to still return the error, but downgrade its gravity, in order to make the program log it, rather than panicking. For sure, an std package such as io is likely not to emit a Fatal error, this would be a decision to be made in higher levels of the application. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
