A
A
Anton2019-07-10 15:31:09
go
Anton, 2019-07-10 15:31:09

Why does it give the warning error strings should not be capitalized or end with punctuation or a newline?

Why does it give the warning error strings should not be capitalized or end with punctuation or a newline?
Here is the code:

package main

import (
  "fmt"
  "net"
)

func localAddresses() {
  ifaces, err := net.Interfaces()
  if err != nil {
    fmt.Print(fmt.Errorf("localddresses: %v", err.Error()))
    return
  }
  for _, i := range ifaces {
    addrs, err := i.Addrs()
    if err != nil {
      fmt.Printf("localaddresses: %v", err.Error()))
      continue
    }
    for _, a := range addrs {
      switch v := a.(type) {
      case *net.IPAddr:
        fmt.Printf("%v : %s (%s)\n", i.Name, v, v.IP.DefaultMask())

      case *net.IPNet:
        fmt.Printf("%v : %s [%v/%v]\n", i.Name, v, v.IP, v.Mask)
      }

    }
  }
}

func main() {
  localAddresses()
}

Here is a screenshot of the error
5d25da7ebf8d3550227848.png
5d25da84d044a869754067.png
Example taken from here
https://stackoverflow.com/questions/23529663/how-t...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2019-07-10
@Zarom

Error Strings
Error strings should not be capitalized (unless beginning with proper nouns or acronyms) or end with punctuation, since they are usually printed following other context . That is, use fmt.Errorf("something bad") not fmt.Errorf("Something bad"), so that log.Printf("Reading %s: %v", filename, err) formats without a spurious capital letter mid -message. This does not apply to logging, which is implicitly line-oriented and not combined inside other messages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question