/
errors.go
44 lines (36 loc) · 1.07 KB
/
errors.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
39
40
41
42
43
44
// Copyright 2015 The Serulian Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package compilercommon
import (
"fmt"
)
// SourceError represents an error produced by a source file at a specific range.
type SourceError struct {
message string
sourceRange SourceRange
}
func (se SourceError) Error() string {
return se.message
}
func (se SourceError) String() string {
return se.message
}
// SourceRange returns the range of this error.
func (se SourceError) SourceRange() SourceRange {
return se.sourceRange
}
// SourceErrorf returns a new SourceError for the given range and message.
func SourceErrorf(sourceRange SourceRange, msg string, args ...interface{}) SourceError {
return SourceError{
message: fmt.Sprintf(msg, args...),
sourceRange: sourceRange,
}
}
// NewSourceError returns a new SourceError for the given range and message.
func NewSourceError(sourceRange SourceRange, msg string) SourceError {
return SourceError{
message: msg,
sourceRange: sourceRange,
}
}