forked from Morganamilo/go-srcinfo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_error.go
38 lines (33 loc) · 1000 Bytes
/
line_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package srcinfo
import (
"fmt"
)
// LineError is an error type that stores the line number at which an error
// occurred as well the full Line that cased the error and an error string.
type LineError struct {
LineNumber int // The line number at which the error occurred
Line string // The line that caused the error
ErrorStr string // An error string
}
// Error Returns an error string in the format:
// "Line <LineNumber>: <ErrorStr>: <Line>".
func (le LineError) Error() string {
return fmt.Sprintf("Line %d: %s: %s", le.LineNumber, le.ErrorStr, le.Line)
}
// Error Returns a new LineError
func Error(LineNumber int, Line string, ErrorStr string) *LineError {
return &LineError{
LineNumber,
Line,
ErrorStr,
}
}
// Errorf Returns a new LineError using the same formatting rules as
// fmt.Printf.
func Errorf(LineNumber int, Line string, ErrorStr string, args ...interface{}) *LineError {
return &LineError{
LineNumber,
Line,
fmt.Sprintf(ErrorStr, args...),
}
}