• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

roblillack / mars / 10575317556

27 Aug 2024 09:19AM UTC coverage: 59.979% (-0.3%) from 60.254%
10575317556

push

github

web-flow
build: Switch to GitHub Actions. #33 (#34)

* Travis update Go versions

* build: Try out GitHub Actions

* Update dependencies.

* Remove Travis & AppVeyor

* Use action-goveralls

* Fix syntax

* Disable fail fast strategy

* Update status badges

2792 of 4655 relevant lines covered (59.98%)

2.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/errors.go
1
package mars
2

3
import (
4
        "fmt"
5
        "strconv"
6
        "strings"
7
)
8

9
// An error description, used as an argument to the error template.
10
type Error struct {
11
        SourceType               string   // The type of source that failed to build.
12
        Title, Path, Description string   // Description of the error, as presented to the user.
13
        Line, Column             int      // Where the error was encountered.
14
        SourceLines              []string // The entire source file, split into lines.
15
        Stack                    string   // The raw stack trace string from debug.Stack().
16
        MetaError                string   // Error that occurred producing the error page.
17
        Link                     string   // A configurable link to wrap the error source in
18
}
19

20
var _ error = &Error{}
21

22
// An object to hold the per-source-line details.
23
type sourceLine struct {
24
        Source  string
25
        Line    int
26
        IsError bool
27
}
28

29
// Construct a plaintext version of the error, taking account that fields are optionally set.
30
// Returns e.g. Compilation Error (in views/header.html:51): expected right delim in end; got "}"
31
func (e *Error) Error() string {
×
32
        if e == nil {
×
33
                return "<nil>"
×
34
        }
×
35

36
        loc := ""
×
37
        if e.Path != "" {
×
38
                line := ""
×
39
                if e.Line != 0 {
×
40
                        line = fmt.Sprintf(":%d", e.Line)
×
41
                }
×
42
                loc = fmt.Sprintf("(in %s%s)", e.Path, line)
×
43
        }
44
        header := loc
×
45
        if e.Title != "" {
×
46
                if loc != "" {
×
47
                        header = fmt.Sprintf("%s %s: ", e.Title, loc)
×
48
                } else {
×
49
                        header = fmt.Sprintf("%s: ", e.Title)
×
50
                }
×
51
        }
52
        return fmt.Sprintf("%s%s", header, e.Description)
×
53
}
54

55
// Returns a snippet of the source around where the error occurred.
56
func (e *Error) ContextSource() []sourceLine {
×
57
        if e.SourceLines == nil {
×
58
                return nil
×
59
        }
×
60
        start := (e.Line - 1) - 5
×
61
        if start < 0 {
×
62
                start = 0
×
63
        }
×
64
        end := (e.Line - 1) + 5
×
65
        if end > len(e.SourceLines) {
×
66
                end = len(e.SourceLines)
×
67
        }
×
68

69
        var lines []sourceLine = make([]sourceLine, end-start)
×
70
        for i, src := range e.SourceLines[start:end] {
×
71
                fileLine := start + i + 1
×
72
                lines[i] = sourceLine{src, fileLine, fileLine == e.Line}
×
73
        }
×
74
        return lines
×
75
}
76

77
func (e *Error) SetLink(errorLink string) {
×
78
        errorLink = strings.Replace(errorLink, "{{Path}}", e.Path, -1)
×
79
        errorLink = strings.Replace(errorLink, "{{Line}}", strconv.Itoa(e.Line), -1)
×
80

×
81
        e.Link = "<a href=" + errorLink + ">" + e.Path + ":" + strconv.Itoa(e.Line) + "</a>"
×
82
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc