1,259 matches across 25 files for error lang:Go
snippet_mode: grep · sorted by relevance
cmd/badges/main.go GO 12 matches · showing 5 view file →
3import (
4 "context"
5 "errors"
6 "fmt"
7 "math"
· · ·
63
64 if filterBad(loc) {
65 log.Error().Str(uniqueCode, "bfee4bd8").Str("loc", loc.String()).Msg("filter bad")
66 return
67 }
· · ·
71 res, err := process(1, loc)
72 if err != nil {
73 log.Error().Str(uniqueCode, "03ec75c3").Err(err).Str("loc", loc.String()).Send()
74 w.WriteHeader(http.StatusBadRequest)
75 _, _ = w.Write([]byte("something bad happened sorry"))
· · ·
108 addr := ":8080"
109 log.Info().Str(uniqueCode, "1876ce1e").Str("addr", addr).Msg("serving")
110 if err := http.ListenAndServe(addr, nil); err != nil && !errors.Is(err, http.ErrServerClosed) {
111 log.Error().Str(uniqueCode, "c28556e8").Err(err).Send()
112 os.Exit(1)
· · ·
111 log.Error().Str(uniqueCode, "c28556e8").Err(err).Send()
112 os.Exit(1)
113 }
+ 7 more matches in this file
cmd/badges/main_test.go GO 5 matches view file →
57 t.Run(tt.name, func(t *testing.T) {
58 if got := resolveColor(tt.color); got != tt.want {
59 t.Errorf("resolveColor(%q) = %q, want %q", tt.color, got, tt.want)
60 }
61 })
· · ·
125 t.Run(tt.name, func(t *testing.T) {
126 if got := formatCount(tt.args.count); got != tt.want {
127 t.Errorf("formatCount() = %v, want %v", got, tt.want)
128 }
129 })
· · ·
170 got, err := processUrlPath(tt.args.path)
171 if (err != nil) != tt.wantErr {
172 t.Errorf("processUrlPath() error = %v, wantErr %v", err, tt.wantErr)
173 return
174 }
· · ·
175 if !reflect.DeepEqual(got, tt.want) {
176 t.Errorf("processUrlPath() got = %v, want %v", got, tt.want)
177 }
178 })
· · ·
298 t.Run(tt.name, func(t *testing.T) {
299 if got := parseBadgeSettings(tt.values); !reflect.DeepEqual(got, tt.want) {
300 t.Errorf("parseBadgeSettings() = %v, want %v", got, tt.want)
301 }
302 })
config.go GO 14 matches · showing 5 view file →
185
186// discoverConfigArgs resolves the global and project config sources
187func discoverConfigArgs(noConfig, findRoot bool, explicitPath string) (globalTokens, projectTokens []string, err error) {
188 // Global source: --config wins, else SCC_CONFIG_PATH (when non-empty and not
189 // disabled), else nothing. No default location, no home-dir stat.
· · ·
202 if readErr != nil {
203 // Explicit source the user asked for: surface and exit non-zero.
204 return nil, nil, fmt.Errorf("could not read config file %q: %w", globalPath, readErr)
205 }
206 globalTokens = tokens
· · ·
229// readConfigFile reads and tokenizes a config source, recording it for trace
230// output and unknown-flag attribution.
231func readConfigFile(path, label string) (tokens []string, err error) {
232 defer func() {
233 if r := recover(); r != nil {
· · ·
234 err = fmt.Errorf("panic while reading config: %v", r)
235 }
236 }()
· · ·
325 return real
326 }
327 boolFunc := func(real func(string) error) func(string) error {
328 if b.inert {
329 return func(string) error { return nil }
+ 9 more matches in this file
config_test.go GO 63 matches · showing 5 view file →
22// runSCCDir runs the test binary as scc in the given working directory, with
23// optional extra environment entries (KEY=VALUE).
24func runSCCDir(t *testing.T, dir string, env []string, args ...string) (string, error) {
25 t.Helper()
26 bin, err := filepath.Abs(sccBinPath)
· · ·
132 got := parseConfigArgs(tc.content, tc.allowPositional)
133 if !slices.Equal(got, tc.want) {
134 t.Errorf("parseConfigArgs(%q, %v) = %q, want %q", tc.content, tc.allowPositional, got, tc.want)
135 }
136 })
· · ·
163 noConfig, findRoot, path := preScanConfig(tc.args)
164 if noConfig != tc.wantNoConfig || findRoot != tc.wantFindRoot || path != tc.wantPath {
165 t.Errorf("preScanConfig(%q) = (%v,%v,%q), want (%v,%v,%q)",
166 tc.args, noConfig, findRoot, path, tc.wantNoConfig, tc.wantFindRoot, tc.wantPath)
167 }
· · ·
175
176 if got := mergeSliceDefault(nil, defaults); !slices.Equal(got, defaults) {
177 t.Errorf("empty set should fall back to defaults, got %q", got)
178 }
179 if got := mergeSliceDefault([]string{"vendor"}, defaults); !slices.Equal(got, []string{".git", ".hg", ".svn", "vendor"}) {
· · ·
180 t.Errorf("defaults should be preserved, got %q", got)
181 }
182 if got := mergeSliceDefault([]string{"vendor", "dist"}, defaults); !slices.Equal(got, []string{".git", ".hg", ".svn", "vendor", "dist"}) {
+ 58 more matches in this file
main.go GO 10 matches · showing 5 view file →
4
5import (
6 "errors"
7 "fmt"
8 "os"
· · ·
15)
16
17func printShellCompletion(cmd *cobra.Command, command string) error {
18 switch command {
19 case "bash":
· · ·
26 return cmd.GenPowerShellCompletion(os.Stdout)
27 default:
28 return errors.New("Unknown shell: " + command)
29 }
30}
· · ·
71 b, err := os.ReadFile(filename)
72 if err != nil {
73 fmt.Fprintf(os.Stderr, "Error reading flags from a file: %s\n", err)
74 os.Exit(1)
75 }
· · ·
89 if !isCompletionInvocation(os.Args) {
90 noConfig, findRoot, explicitPath := preScanConfig(os.Args)
91 var discoverErr error
92 globalTokens, projectTokens, discoverErr = discoverConfigArgs(noConfig, findRoot, explicitPath)
93 if discoverErr != nil {
+ 5 more matches in this file
main_test.go GO 33 matches · showing 5 view file →
29}
30
31func runSCC(args ...string) (string, error) {
32 args = slices.Insert(args, 0, sccTestFlag)
33 cmd := exec.Command(sccBinPath, args...)
· · ·
269 }
270 if !strings.Contains(output, "MATLAB") {
271 t.Errorf("can not find MATLAB, output: %s", output)
272 }
273 if !strings.Contains(output, "Objective C") {
· · ·
274 t.Errorf("can not find Objective C, output:\n%s", output)
275 }
276}
· · ·
280 output, err := runSCC("--not-a-real-option")
281 if err == nil {
282 t.Fatal("scc should exit with error code")
283 }
284 if !strings.Contains(output, "Error: unknown flag: --not-a-real-option") {
· · ·
284 if !strings.Contains(output, "Error: unknown flag: --not-a-real-option") {
285 t.Fatalf("scc should report invalid options, output:\n%s", output)
286 }
+ 28 more matches in this file
mcp.go GO 16 matches · showing 5 view file →
147
148 errLogger := log.New(os.Stderr, "scc-mcp: ", log.LstdFlags)
149 if err := server.ServeStdio(mcpServer, server.WithErrorLogger(errLogger)); err != nil {
150 _, _ = fmt.Fprintf(os.Stderr, "scc-mcp: server error: %v\n", err)
151 os.Exit(1)
· · ·
150 _, _ = fmt.Fprintf(os.Stderr, "scc-mcp: server error: %v\n", err)
151 os.Exit(1)
152 }
· · ·
218}
219
220func mcpAnalyzeHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
221 args := request.GetArguments()
222
· · ·
230 absPath, err := filepath.Abs(path)
231 if err != nil {
232 return mcp.NewToolResultError(fmt.Sprintf("invalid path: %v", err)), nil
233 }
234
· · ·
235 // Verify path can be accessed
236 if _, err := os.Stat(absPath); err != nil {
237 return mcp.NewToolResultError(fmt.Sprintf("path cannot be accessed: %s: %v", absPath, err)), nil
238 }
239
+ 11 more matches in this file
mcp_test.go GO 20 matches · showing 5 view file →
108 result, err := mcpAnalyzeHandler(context.Background(), req)
109 if err != nil {
110 t.Fatalf("mcpAnalyzeHandler returned error: %v", err)
111 }
112 if result.IsError {
· · ·
112 if result.IsError {
113 t.Fatalf("mcpAnalyzeHandler returned tool error: %+v", result.Content)
114 }
· · ·
113 t.Fatalf("mcpAnalyzeHandler returned tool error: %+v", result.Content)
114 }
115 if len(result.Content) == 0 {
· · ·
139
140// callCoupling invokes the coupling MCP handler with the given arguments and
141// returns the result, failing the test on a transport-level (non-tool) error.
142func callCoupling(t *testing.T, args map[string]any) *mcp.CallToolResult {
143 t.Helper()
· · ·
147 res, err := mcpCouplingHandler(context.Background(), req)
148 if err != nil {
149 t.Fatalf("handler returned transport error: %v", err)
150 }
151 if res == nil {
+ 15 more matches in this file
processor/cocomo_test.go GO 9 matches · showing 5 view file →
15 // Should be around 582
16 if got < 580 || got > 585 {
17 t.Errorf("Got %f", got)
18 }
19}
· · ·
25 // Should be around 2602469
26 if got < 2602460 || got > 2602480 {
27 t.Errorf("Got %f", got)
28 }
29}
· · ·
35 // Should be around 2.7
36 if got < 2.6 || got > 2.8 {
37 t.Errorf("Got %f", got)
38 }
39}
· · ·
50 want := eff * (56286.0 / 12.0) * 2.4
51 if math.Abs(got-want) > 1e-6 {
52 t.Errorf("EstimateCost truncated the monthly wage: got %v want %v (diff %v)", got, want, got-want)
53 }
54}
· · ·
186
187 if tt.wantEffort != 0 && !floatApproxEqual(effort, tt.wantEffort) {
188 t.Errorf("effort = %v, want %v", effort, tt.wantEffort)
189 }
190 if tt.wantSched != 0 && !floatApproxEqual(sched, tt.wantSched) {
+ 4 more matches in this file
processor/cognitive_nesting_test.go GO 11 matches · showing 5 view file →
72 for name, job := range map[string]FileJob{"deep": deep, "deNested": mid, "flat": shallow} {
73 if job.Complexity != 4 {
74 t.Errorf("%s: expected Complexity 4 (four ifs), got %d", name, job.Complexity)
75 }
76 }
· · ·
78 // Exact cognitive values from the 1+nesting rule.
79 if deep.Cognitive != 14 {
80 t.Errorf("deepChain Cognitive: expected 14, got %d", deep.Cognitive)
81 }
82 if mid.Cognitive != 10 {
· · ·
83 t.Errorf("deNested Cognitive: expected 10, got %d", mid.Cognitive)
84 }
85 if shallow.Cognitive != 8 {
· · ·
86 t.Errorf("flat Cognitive: expected 8, got %d", shallow.Cognitive)
87 }
88
· · ·
90 // strictly higher, even at identical cyclomatic complexity.
91 if !(deep.Cognitive > mid.Cognitive && mid.Cognitive > shallow.Cognitive) {
92 t.Errorf("expected deep > deNested > flat, got %d, %d, %d",
93 deep.Cognitive, mid.Cognitive, shallow.Cognitive)
94 }
+ 6 more matches in this file
processor/constants.go GO 1 matches view file →
697 "else if ",
698 "try ",
699 "on error ",
700 "and ",
701 "or ",
processor/detector.go GO 7 matches · showing 5 view file →
6 "bytes"
7 "cmp"
8 "errors"
9 "slices"
10 "strings"
· · ·
12
13var (
14 errMissingShebang = errors.New("missing shebang")
15 errUnknownShebang = errors.New("unknown shebang")
16 errUnableToDetermineShebangCmd = errors.New("unable to determine shebang command")
· · ·
15 errUnknownShebang = errors.New("unknown shebang")
16 errUnableToDetermineShebangCmd = errors.New("unable to determine shebang command")
17)
· · ·
16 errUnableToDetermineShebangCmd = errors.New("unable to determine shebang command")
17)
18
· · ·
19// DetectLanguage detects a language based on the filename returns the language extension and error
20func DetectLanguage(name string) ([]string, string) {
21 extension := ""
+ 2 more matches in this file
processor/detector_test.go GO 46 matches · showing 5 view file →
15
16 if ext != "css" {
17 t.Error("Expected css got", ext)
18 }
19 AllowListExtensions = []string{}
· · ·
30 possible, extension := DetectLanguage(filename)
31 if extension != wantExtension {
32 t.Errorf("DetectLanguage(%q) extension = %q, want %q", filename, extension, wantExtension)
33 }
34 if !slices.Contains(possible, "Mojo") {
· · ·
35 t.Errorf("DetectLanguage(%q) languages = %v, want Mojo", filename, possible)
36 }
37 }
· · ·
44
45 if x != "" || y == nil {
46 t.Error("Expected no match got", x)
47 }
48
· · ·
50
51 if x != "" || y == nil {
52 t.Error("Expected no match got", x)
53 }
54}
+ 41 more matches in this file
processor/duplicates_test.go GO 1 matches view file →
46 for i := range first {
47 if first[i].Count != second[i].Count {
48 t.Errorf("language %s: first run counted %d files, second counted %d", first[i].Name, first[i].Count, second[i].Count)
49 }
50 }
processor/file.go GO 3 matches view file →
66 }
67
68 var err error
69 symPath, err = filepath.EvalSymlinks(path)
70 if err != nil {
· · ·
71 printError(err.Error())
72 return nil
73 }
· · ·
74 fileInfo, err = os.Lstat(symPath)
75 if err != nil {
76 printError(err.Error())
77 return nil
78 }
processor/file_test.go GO 25 matches · showing 5 view file →
16
17 if got != expected {
18 t.Errorf("Expected %s got %s", expected, got)
19 }
20}
· · ·
25
26 if got != expected {
27 t.Errorf("Expected %s got %s", expected, got)
28 }
29}
· · ·
34
35 if got != expected {
36 t.Errorf("Expected %s got %s", expected, got)
37 }
38}
· · ·
43
44 if got != expected {
45 t.Errorf("Expected %s got %s", expected, got)
46 }
47}
· · ·
52
53 if got != expected {
54 t.Errorf("Expected %s got %s", expected, got)
55 }
56}
+ 20 more matches in this file
processor/filereader.go GO 3 matches view file →
22
23// ReadFile actually reads the file into a buffer size controlled by LargeByteCount
24func (reader *FileReader) ReadFile(path string, size int) ([]byte, error) {
25 fd, err := os.Open(path)
26 if err != nil {
· · ·
27 return nil, fmt.Errorf("error opening %s: %v", path, err)
28 }
29 defer func(file *os.File) {
· · ·
46 _, err = reader.Buffer.ReadFrom(fd)
47 if err != nil {
48 return nil, fmt.Errorf("error reading %s: %w", path, err)
49 }
50
processor/formatters_cognitive_test.go GO 23 matches · showing 5 view file →
49
50 if !strings.Contains(res, "Cognitive") {
51 t.Errorf("wide cognitive output missing Cognitive header:\n%s", res)
52 }
53 // language total and grand total are both 11 + 20 = 31
· · ·
54 if !strings.Contains(res, "31") {
55 t.Errorf("wide cognitive output missing summed cognitive 31:\n%s", res)
56 }
57}
· · ·
64
65 if strings.Contains(res, "Cognitive") {
66 t.Errorf("wide output leaked Cognitive column while disabled:\n%s", res)
67 }
68 // Break lines must stay at the original 109-rune width when disabled.
· · ·
69 for _, line := range strings.Split(res, "\n") {
70 if strings.HasPrefix(line, "─") && len([]rune(line)) != 109 {
71 t.Errorf("disabled wide break width changed: got %d want 109", len([]rune(line)))
72 }
73 }
· · ·
85
86 if !strings.Contains(res, "Complexity") {
87 t.Errorf("short view lost the Complexity header:\n%s", res)
88 }
89 if strings.Contains(res, "Cognitive") {
+ 18 more matches in this file
processor/formatters_percent_test.go GO 2 matches view file →
41 res := fn(job())
42 if strings.Contains(res, "NaN") {
43 t.Errorf("expected no NaN in --percent output, got:\n%s", res)
44 }
45 if !strings.Contains(res, "0.0%") {
· · ·
46 t.Errorf("expected a 0.0%% entry for the empty categories, got:\n%s", res)
47 }
48 })
processor/formatters_test.go GO 118 matches · showing 5 view file →
20
21 if !strings.Contains(str.String(), "Estimated Schedule Effort (organic) 0.22 months") {
22 t.Error("expected to match got", str.String())
23 }
24}
· · ·
30
31 if !strings.Contains(str.String(), "Processed 1 bytes, 0.000 megabytes (SI)") {
32 t.Error("expected to match got", str.String())
33 }
34}
· · ·
41 // The byte count is locale-grouped like every other number in the output.
42 if !strings.Contains(str.String(), "Processed 1,000,000 bytes, 1.000 megabytes (SI)") {
43 t.Error("expected to match got", str.String())
44 }
45}
· · ·
57 // expectation year-independent.
58 if got := xkcdKbDivisor(2026); got != float64(1024*1024) {
59 t.Errorf("xkcdKbDivisor(2026) = %v, want %d (non-leap, 1024-based)", got, 1024*1024)
60 }
61 if got := xkcdKbDivisor(2024); got != 1_000_000.0 {
· · ·
62 t.Errorf("xkcdKbDivisor(2024) = %v, want 1000000 (leap, 1000-based)", got)
63 }
64
+ 113 more matches in this file
processor/helpers_test.go GO 2 matches view file →
13
14 if res == makeTimestampNano() {
15 t.Error("Should not match")
16 }
17}
· · ·
22
23 if res == makeTimestampMilli() {
24 t.Error("Should not match")
25 }
26}
processor/history.go GO 20 matches · showing 5 view file →
5import (
6 "context"
7 "errors"
8 "fmt"
9 "io"
· · ·
126// collected --depth commits. iter.ForEach surfaces whatever the callback
127// returns, so we can compare it back at the call site directly.
128var errStopIter = errors.New("history: stop iteration")
129
130// Bucketing divides [From, To] into N equal time slices. Used by the timeline
· · ·
202// (newest first → oldest first), and feeds every commit's first-parent diff
203// to the observer.
204func runHistory(repoPath string, observer CommitObserver) (HistoryWindow, error) {
205 // Turn GC back on because we have no idea how much we are about to process
206 EnableGc()
· · ·
208 repo, err := git.PlainOpenWithOptions(repoPath, &git.PlainOpenOptions{DetectDotGit: true})
209 if err != nil {
210 return HistoryWindow{}, fmt.Errorf("open git repository: %w", err)
211 }
212
· · ·
213 head, err := repo.Head()
214 if err != nil {
215 if errors.Is(err, plumbing.ErrReferenceNotFound) {
216 observer.Finalise(HistoryWindow{}, emptySnapshot())
217 return HistoryWindow{}, nil
+ 15 more matches in this file
processor/history_author_timeline.go GO 6 matches · showing 5 view file →
190// when --by-author --timeline is set. Opens the repo, walks the window with
191// the configured bucket count, and writes the chosen format.
192func runAuthorTimelineReport(repoPath string) error {
193 observer := newHistoryAuthorTimelineObserver(HistoryBuckets)
194 if _, err := runHistory(repoPath, observer); err != nil {
· · ·
210}
211
212func renderAuthorTimeline(o *historyAuthorTimelineObserver) (string, error) {
213 switch strings.ToLower(Format) {
214 case "", "tabular", "wide":
· · ·
219 return renderAuthorTimelineJSON(o)
220 default:
221 return "", fmt.Errorf("unsupported --format %q for --by-author --timeline (supported: tabular, csv, json)", Format)
222 }
223}
· · ·
361}
362
363func renderAuthorTimelineCSV(o *historyAuthorTimelineObserver) (string, error) {
364 var sb strings.Builder
365 sb.WriteString(formatWindowComment(o.window))
· · ·
383 }
384 w.Flush()
385 if err := w.Error(); err != nil {
386 return "", err
387 }
+ 1 more matches in this file
processor/history_author_timeline_test.go GO 28 matches · showing 5 view file →
108 for _, c := range cases {
109 if got := b.Index(c.t); got != c.want {
110 t.Errorf("Index(%s) = %d, want %d", c.t, got, c.want)
111 }
112 }
· · ·
117 b := NewBucketing(when, when, 8)
118 if got := b.Index(when); got != 0 {
119 t.Errorf("degenerate window: Index = %d, want 0", got)
120 }
121 if got := b.Index(when.Add(time.Hour)); got != 0 {
· · ·
122 t.Errorf("degenerate window: future Index = %d, want 0", got)
123 }
124}
· · ·
129 b := NewBucketing(from, to, 10)
130 if got := b.Start(0); !got.Equal(from) {
131 t.Errorf("Start(0) = %s, want %s", got, from)
132 }
133 if got := b.Start(5); !got.Equal(from.Add(5 * 24 * time.Hour)) {
· · ·
134 t.Errorf("Start(5) = %s, want %s", got, from.Add(5*24*time.Hour))
135 }
136}
+ 23 more matches in this file
processor/history_authors.go GO 6 matches · showing 5 view file →
372// walks history with baseline seeding, and writes the chosen format to
373// stdout or FileOutput.
374func runAuthorsReport(repoPath string) error {
375 observer := newHistoryAuthorsObserver()
376 if _, err := runHistory(repoPath, observer); err != nil {
· · ·
392}
393
394func renderAuthors(o *historyAuthorsObserver) (string, error) {
395 switch strings.ToLower(Format) {
396 case "", "tabular", "wide":
· · ·
401 return renderAuthorsJSON(o)
402 default:
403 return "", fmt.Errorf("unsupported --format %q for --by-author (supported: tabular, csv, json)", Format)
404 }
405}
· · ·
582}
583
584func renderAuthorsCSV(o *historyAuthorsObserver) (string, error) {
585 var sb strings.Builder
586 sb.WriteString(formatWindowComment(o.window))
· · ·
615 }
616 w.Flush()
617 if err := w.Error(); err != nil {
618 return "", err
619 }
+ 1 more matches in this file
Search syntax
auth loginboth terms (AND is implicit)
auth OR logineither term
NOT path:vendorexclude matches
"exact phrase"quoted exact match
/func\s+Test/regex
handler~1fuzzy (Levenshtein 1)
file:*_test.gofilename glob
path:pkg/auth/**full path glob
lang:golanguage filter

Search any public repo from your terminal

This page calls POST /api/v1/code_search. Same tool, available over MCP for Claude/Cursor/Copilot.