5 ms·
I'm new to Go - but it looks like the example code completely ignores the error codes. Is that a common thing?
by lima 9y ago
I'm new to Go - but it looks like the example code completely ignores the error codes.
Is that a common thing?
- yalue 9y agoIt isn't common, and the code example wouldn't even compile because "err" is assigned but never used. I imagine that they included the "err" variables to show that they're available, but didn't want to clutter the example with error checks. You can ignore error codes in go by assigning them to the special variable "_", but, outside of very short toy examples, it is a huge warning sign for terrible code. It's certainly not common to ignore errors in Go.
- mschoch 9y agoYou are correct. I think when I originally designed the homepage I wanted to show how you index and search in just a few lines. I thought omitting the error handling boilerplate was acceptable, but properly handling these errors is also key for a good initial experience. So I'm persuaded to at least revisit the decision. https://github.com/blevesearch/blevesearch.github.io-hugo/issues/12 https://github.com/blevesearch/blevesearch.github.io-hugo/is...
- roblaszczak 9y agofor examples like this it is much better to explicit ignore error: _ = index.Index(identifier, your_data) it will also pass https://github.com/kisielk/errcheck https://github.com/kisielk/errcheck check eventually we can just panic error if err := index.Index(identifier, your_data); err != nil { panic(err) }