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

ory / keto / 19929347875

04 Dec 2025 12:41PM UTC coverage: 50.769% (-0.1%) from 50.876%
19929347875

push

github

ory-bot
chore: fix golangci-lint warnings

GitOrigin-RevId: 05ddc40c2

24 of 50 new or added lines in 20 files covered. (48.0%)

5 existing lines in 2 files now uncovered.

3831 of 7546 relevant lines covered (50.77%)

0.57 hits per line

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

39.77
/internal/schema/parse_errors.go
1
// Copyright © 2023 Ory Corp
2
// SPDX-License-Identifier: Apache-2.0
3

4
package schema
5

6
import (
7
        "fmt"
8
        "math"
9
        "strings"
10
        "unicode"
11

12
        "github.com/ory/keto/ketoapi"
13
        opl "github.com/ory/keto/proto/ory/keto/opl/v1alpha1"
14
)
15

16
type (
17
        ParseError struct {
18
                msg  string
19
                item item
20
                p    *parser
21
        }
22
)
23

24
func max(a, b int) int {
×
25
        if a > b {
×
26
                return a
×
27
        }
×
28
        return b
×
29
}
30

31
func (e *ParseError) Error() string {
×
32
        var s strings.Builder
×
33
        start := e.toSrcPos(e.item.Start)
×
34
        end := e.toSrcPos(e.item.End)
×
35
        rows := e.rows()
×
36
        startLineIdx := max(start.Line-2, 0)
×
37
        errorLineIdx := max(start.Line-1, 0)
×
38

×
39
        s.WriteString(fmt.Sprintf("error from %d:%d to %d:%d: %s\n\n",
×
40
                start.Line, start.Col,
×
41
                end.Line, end.Col,
×
42
                e.msg))
×
43

×
44
        if len(rows) < start.Line {
×
45
                s.WriteString("meta error: could not find source position in input\n")
×
46
                return s.String()
×
47
        }
×
48

49
        for line := startLineIdx; line <= errorLineIdx; line++ {
×
50
                s.WriteString(fmt.Sprintf("%4d | %s\n", line, rows[line]))
×
51
        }
×
52
        s.WriteString("     | ")
×
53
        for i, r := range rows[errorLineIdx] {
×
54
                switch {
×
55
                case start.Col == i:
×
56
                        s.WriteRune('^')
×
57
                case start.Col <= i && i <= end.Col-1:
×
58
                        s.WriteRune('~')
×
59
                case unicode.IsSpace(r):
×
60
                        s.WriteRune(r)
×
61
                default:
×
62
                        s.WriteRune(' ')
×
63
                }
64
        }
65
        s.WriteRune('\n')
×
66

×
67
        if errorLineIdx+1 < len(rows) {
×
68
                s.WriteString(fmt.Sprintf("%4d | %s\n", errorLineIdx+1, rows[errorLineIdx+1]))
×
69
                s.WriteRune('\n')
×
70
        }
×
71

72
        return s.String()
×
73
}
74

75
func (e *ParseError) ToAPI() *ketoapi.ParseError {
1✔
76
        return &ketoapi.ParseError{
1✔
77
                Message: e.msg,
1✔
78
                Start:   e.toSrcPos(e.item.Start),
1✔
79
                End:     e.toSrcPos(e.item.End),
1✔
80
        }
1✔
81
}
1✔
82
func (e *ParseError) ToProto() *opl.ParseError {
1✔
83
        start := e.toSrcPos(e.item.Start)
1✔
84
        end := e.toSrcPos(e.item.End)
1✔
85
        return &opl.ParseError{
1✔
86
                Message: e.msg,
1✔
87
                Start: &opl.SourcePosition{
1✔
88
                        Line:   clampUint32(start.Line),
1✔
89
                        Column: clampUint32(start.Col),
1✔
90
                },
1✔
91
                End: &opl.SourcePosition{
1✔
92
                        Line:   clampUint32(end.Line),
1✔
93
                        Column: clampUint32(end.Col),
1✔
94
                },
1✔
95
        }
1✔
96
}
1✔
97

98
// toSrcPos converts the given position in the input to a Line and column
99
// number.
100
func (e *ParseError) toSrcPos(pos int) (srcPos ketoapi.SourcePosition) {
1✔
101
        srcPos.Line = 1
1✔
102
        for _, c := range e.p.lexer.input {
2✔
103
                srcPos.Col++
1✔
104
                pos--
1✔
105
                if pos <= 0 {
2✔
106
                        break
1✔
107
                }
108
                if c == '\n' {
1✔
109
                        srcPos.Line++
×
110
                        srcPos.Col = 0
×
111
                }
×
112
        }
113
        return
1✔
114
}
115

116
func clampUint32(v int) uint32 {
1✔
117
        switch {
1✔
NEW
118
        case v < 0:
×
NEW
119
                return 0
×
NEW
120
        case v > math.MaxUint32:
×
NEW
121
                return math.MaxUint32
×
122
        default:
1✔
123
                return uint32(v)
1✔
124
        }
125
}
126

127
func (e *ParseError) rows() []string {
×
128
        return strings.Split(e.p.lexer.input, "\n")
×
129
}
×
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

© 2025 Coveralls, Inc