FAQ
Hello,

Is there any possibility that compiler or other tools can help me find out
where I ignore error or don't handle it?

Example:

....
obj.DoSomething()
....

if DoSomething returns error, could I run some tool to tell me I am
ignoring error in my program?

Similarly, other two cases where I have trouble:

1. I assign err to something, but don't check it
2. I assign err to something, have if err != nil {...}, but no else

Tools to help me find these cases would be great. Right now I am trying to
be human compiler finding such cases ;-) I try to be careful but sometimes
I still forget.

--

Search Discussions

  • Kyle Lemons at Dec 24, 2012 at 1:25 am
    The tool for the task would be `go vet` but it doesn't currently have any
    such tests.

    I think that exp/types will probably have the functionality needed to
    implement at least some of what you ask when it graduates to the standard
    library.

    On Sun, Dec 23, 2012 at 2:09 PM, Boris Solovyov wrote:

    Hello,

    Is there any possibility that compiler or other tools can help me find out
    where I ignore error or don't handle it?

    Example:

    ....
    obj.DoSomething()
    ....

    if DoSomething returns error, could I run some tool to tell me I am
    ignoring error in my program?

    Similarly, other two cases where I have trouble:

    1. I assign err to something, but don't check it
    The compiler should catch you if you don't reuse err.

    2. I assign err to something, have if err != nil {...}, but no else
    The case where you *do *have an else is much more rare, in my experience.

    Tools to help me find these cases would be great. Right now I am trying to
    be human compiler finding such cases ;-) I try to be careful but sometimes
    I still forget.

    --

    --
  • Boris Solovyov at Dec 26, 2012 at 4:10 pm
    Hi,
    On Sun, Dec 23, 2012 at 8:25 PM, Kyle Lemons wrote:

    1. I assign err to something, but don't check it
    The compiler should catch you if you don't reuse err.
    Yes, but idiomatic use of err can look like this:

    foo, err := something()
    if err != nil {
    ...
    } else {
    bar, err := something()
    baz(bar)
    }

    Now I didn't check err the second time, but compiler doesn't catch. I think
    couple of times I made that mistake.

    --
  • Bryanturley at Dec 26, 2012 at 4:13 pm

    On Wednesday, December 26, 2012 10:10:09 AM UTC-6, Boris wrote:
    Hi,

    On Sun, Dec 23, 2012 at 8:25 PM, Kyle Lemons <kev...@google.com<javascript:>
    wrote:
    1. I assign err to something, but don't check it
    The compiler should catch you if you don't reuse err.
    Yes, but idiomatic use of err can look like this:

    foo, err := something()
    if err != nil {
    ...
    } else {
    bar, err := something()
    baz(bar)
    }

    Now I didn't check err the second time, but compiler doesn't catch. I
    think couple of times I made that mistake.
    http://play.golang.org/p/iK1C3UgL2v you sure the compiler did catch it?



    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 23, '12 at 7:09p
activeDec 26, '12 at 4:13p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase