Standard library / go/scanner

go/scanner.Error.Error()

Formats a diagnostic with its source position when available. Expected stdout: 'demo.go:1:2: bad token\n'.

Formal Syntax & Structure

go syntaxgo
func (e Error) Error() string

Return Value

string

Formats a diagnostic with its source position when available.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/scanner"  "go/token")
func main() {  e := scanner.Error{Pos: token.Position{Filename: "demo.go", Line: 1, Column: 2}, Msg: "bad token"}  fmt.Println(e.Error())}
Go Reference