具有%e错误的字符串格式

I've encountered some go code that appears to use %e for formatting an error for display to the screen. A simplified version would be code like this

err := errors.New("La de da")
fmt.Printf("%e
", err)

outputs

&{%!e(string=La de da)}

However, if I look at the go manual, it says %e is for formatting floating point numbers in scientific notation. That output doesn't look like scientific notation, so I'm wondering

  1. If this is a specific notation, what is it? (i.e. is there a %. formatting option I could use to get that format)

  2. If it's not a specific notation, what weird thing is going on under the hood that leads to an error being rendered in this way?

  3. What silly, obvious thing am I missing that renders most of what I've said in this post wrong?

Read the Go documentation.

Package fmt

Printing

Format errors:

If an invalid argument is given for a verb, such as providing a string to %d, the generated string will contain a description of the problem, as in these examples:

Wrong type or unknown verb: %!verb(type=value)
  Printf("%d", hi):          %!d(string=hi)
Too many arguments: %!(EXTRA type=value)
  Printf("hi", "guys"):      hi%!(EXTRA string=guys)
Too few arguments: %!verb(MISSING)
  Printf("hi%d"):            hi%!d(MISSING)
Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC)
  Printf("%*s", 4.5, "hi"):  %!(BADWIDTH)hi
  Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi
Invalid or invalid use of argument index: %!(BADINDEX)
  Printf("%*[2]d", 7):       %!d(BADINDEX)
  Printf("%.[2]d", 7):       %!d(BADINDEX)

All errors begin with the string "%!" followed sometimes by a single character (the verb) and end with a parenthesized description.


For your example,

package main

import (
    "errors"
    "fmt"
)

func main() {
    err := errors.New("La de da")
    fmt.Printf("%e
", err)
}

Playground: https://play.golang.org/p/NKC6WWePyxM

Output:

&{%!e(string=La de da)}

Documentation:

All errors begin with the string "%!" followed sometimes by a single character (the verb) and end with a parenthesized description.

Wrong type or unknown verb: %!verb(type=value)
  Printf("%d", hi):          %!d(string=hi)