What are some cases where errors can be ignored? And if they can be, are these neccesarily some sort of "status" rather than "error"?
What are some cases where errors can be ignored? And if they can be, are these neccesarily some sort of "status" rather than "error"?
How likely is the error going to happen, if you know (through tests and everything) that the query is correct?
it can only happen in two scenarios:
1. the database has serious problems 2. the driver is incorrect
in normal cases you would probably handle that with a middleware in classical languages. i.e. you would have a middlewre that catches exceptions and handle the error there (logging, paging, whatever) and maybe show a nice looking "we are experience problems now"-page.
in golang this is a little bit harder, since you would need to handle the error by every caller and with the default http interface you would actually need to call your "handle default error" in every http handler.
One could argue that the side effect is part of the error, and really what you are ignoring are the details of an error (e.g. did the config entry fail to load because the config file wasn't found, because of filesystem permissions, or because the particular configuration key wasn't present?)
var s Settings
if s, err := load_settings(); err != nil {
s = defaults()
}
Where is the unhandled error?Here's a playground showing the issue: https://play.golang.org/p/eE0HEZx1MJu
Go is full of nice little foot-guns like that :)
You would want to also have 'var err error' above the block and use '=' instead of ':=' to fix this sort of issue.
package main
type HowOdd interface {
Poke() string
}
type AConcreteThing struct {
}
func (t *AConcreteThing) Poke() string { return "hehe" }
func DoAConcreteThing() *AConcreteThing {
return nil
}
func DoAThing() HowOdd {
return DoAConcreteThing()
}
func main() {
lolWhat := DoAThing()
if lolWhat != nil {
panic("How could this happen?")
}
}
I understand that the interface at the bottom is a non-null interface containing a null value, but...damn, that sucks.