forked from mmcloughlin/avo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: include position information in errors
Updates mmcloughlin#5
- Loading branch information
1 parent
80c427d
commit 05cfa80
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package build | ||
|
||
import ( | ||
"github.com/mmcloughlin/avo/internal/stack" | ||
"github.com/mmcloughlin/avo/src" | ||
) | ||
|
||
// Error represents an error during building, optionally tagged with the position at which it happened. | ||
type Error struct { | ||
Position src.Position | ||
Err error | ||
} | ||
|
||
// exterr constructs an Error with position derived from the first frame in the | ||
// call stack outside this package. | ||
func exterr(err error) Error { | ||
e := Error{Err: err} | ||
if f := stack.ExternalCaller(); f != nil { | ||
e.Position = src.FramePosition(*f).Relwd() | ||
} | ||
return e | ||
} | ||
|
||
func (e Error) Error() string { | ||
msg := e.Err.Error() | ||
if e.Position.IsValid() { | ||
return e.Position.String() + ": " + msg | ||
} | ||
return msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters