Skip to content

bogus io.EOF error when error var is predeclared #15

Closed
@kolyshkin

Description

@kolyshkin

I have previously submitted #12 hoping it would fix to eliminate a bogus error in my code.

Today I found it did not.

The following code is fine (i.e. no warnings):

func UseBufioReadLine(r io.Reader) error {
       rd := bufio.NewReader(r)
       for {
               _, _, err := rd.ReadLine()
               if err != nil {
                       if err == io.EOF {
                               err = nil
                       }
               }
               return err
       }
}

but if we modify it in this way:

 func UseBufioReadLine(r io.Reader) error {
        rd := bufio.NewReader(r)
+       var err error
        for {
-               _, _, err := rd.ReadLine()
+               _, _, err = rd.ReadLine()
                if err != nil {
                        if err == io.EOF {

we will have something like

func UseBufioReadLine(r io.Reader) error {
          rd := bufio.NewReader(r)
          var err error
          for {
                  _, _, err = rd.ReadLine()
                  if err != nil {
                          if err == io.EOF {
                                  err = nil
                          }
                  }
                  return err
          }
  }

and this code results in a warning:

comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error

Alas, I don't know internals good enough to try to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions