505 matches across 25 files for error lang:Go lang:Go lang:Go lang:Go
snippet_mode: auto · sorted by relevance
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
678
679 fileWalker := gocodewalker.NewParallelFileWalker(dirPaths, potentialFilesQueue)
680▶ fileWalker.SetErrorHandler(func(e error) bool {
681 printError(e.Error())
682 return true
· · ·
681▶ printError(e.Error())
682 return true
683 })
· · ·
701 excludePathRegexes = append(excludePathRegexes, regexpResult)
702 } else {
703▶ printError(err.Error())
704 }
705 }
· · ·
708 err := fileWalker.Start()
709 if err != nil {
710▶ printError(err.Error())
711 }
712 }()
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
81
82 errLogger := log.New(os.Stderr, "scc-mcp: ", log.LstdFlags)
83▶ if err := server.ServeStdio(mcpServer, server.WithErrorLogger(errLogger)); err != nil {
84 _, _ = fmt.Fprintf(os.Stderr, "scc-mcp: server error: %v\n", err)
85 os.Exit(1)
· · ·
84▶ _, _ = fmt.Fprintf(os.Stderr, "scc-mcp: server error: %v\n", err)
85 os.Exit(1)
86 }
· · ·
149}
150
151▶func mcpAnalyzeHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
152 args := request.GetArguments()
153
· · ·
161 absPath, err := filepath.Abs(path)
162 if err != nil {
163▶ return mcp.NewToolResultError(fmt.Sprintf("invalid path: %v", err)), nil
164 }
165
· · ·
166 // Verify path can be accessed
167 if _, err := os.Stat(absPath); err != nil {
168▶ return mcp.NewToolResultError(fmt.Sprintf("path cannot be accessed: %s: %v", absPath, err)), nil
169 }
170
+ 3 more matches in this 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 }
16// ProcessResult runs the same pipeline as Process but returns structured results
17// instead of formatting to stdout. Useful for programmatic consumers like MCP servers.
18▶func ProcessResult() ([]LanguageSummary, error) {
19 ProcessConstants()
20 processFlags()
· · ·
33 s, err := os.Stat(fpath)
34 if err != nil {
35▶ return nil, fmt.Errorf("file or directory could not be read: %s", fpath)
36 }
37
· · ·
55
56 fileWalker := gocodewalker.NewParallelFileWalker(dirPaths, potentialFilesQueue)
57▶ fileWalker.SetErrorHandler(func(e error) bool {
58 printError(e.Error())
59 return true
· · ·
58▶ printError(e.Error())
59 return true
60 })
· · ·
78 excludePathRegexes = append(excludePathRegexes, regexpResult)
79 } else {
80▶ printError(err.Error())
81 }
82 }
+ 1 more matches in this file
30// Reads all .json files in the current folder
31// and encodes them as strings literals in constants.go
32▶func generateConstants() error {
33 files, _ := os.ReadDir(".")
34 buf := &bytes.Buffer{}
· · ·
40 f, err := os.Open(f.Name())
41 if err != nil {
42▶ return fmt.Errorf("failed to open file '%s': %v", f.Name(), err)
43 }
44 defer func(file *os.File) {
· · ·
50 // validate the json by decoding into an empty struct
51 if err := json.NewDecoder(f).Decode(&data); err != nil {
52▶ return fmt.Errorf("failed to validate json in file '%s': %v", f.Name(), err)
53 }
54
· · ·
61 }).Parse(langTemplate)
62 if err != nil {
63▶ return fmt.Errorf("failed to parse template file: %v", err)
64 }
65
· · ·
66 if err := t.Execute(buf, langs); err != nil {
67▶ return fmt.Errorf("failed to execute template file: %v", err)
68 }
69
+ 5 more matches in this file
4
5import (
6▶ "errors"
7 "fmt"
8 "os"
· · ·
15)
16
17▶func 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}
· · ·
66 b, err := os.ReadFile(filepath)
67 if err != nil {
68▶ fmt.Printf("Error reading flags from a file: %s\n", err)
69 os.Exit(1)
70 }
· · ·
545 err := printShellCompletion(rootCmd, args[3])
546 if err != nil {
547▶ _, _ = fmt.Fprintf(os.Stderr, "Error printing shell completion: %s\n", err)
548 }
549 return
+ 3 more matches in this file
14 levelDebug
15 levelWarn
16▶ levelError
17)
18
· · ·
25 case levelWarn:
26 return "WARN"
27▶ case levelError:
28 return "ERROR"
29 default:
· · ·
28▶ return "ERROR"
29 default:
30 return ""
· · ·
92
93// Used when explicitly for os.exit output when crashing out
94▶func printError(msg string) {
95 doPrint(os.Stderr, levelError, msg, nil)
96}
· · ·
95▶ doPrint(os.Stderr, levelError, msg, nil)
96}
97
17func TestIsWhitespace(t *testing.T) {
18 if !isWhitespace(' ') {
19▶ t.Errorf("Expected to be true")
20 }
21}
· · ·
25
26 if !isBinary(0, 0) {
27▶ t.Errorf("Expected to be true")
28 }
29}
· · ·
33
34 if isBinary(0, 0) {
35▶ t.Errorf("Expected to be false")
36 }
37}
· · ·
51 CountStats(&fileJob)
52 if fileJob.Lines != 0 {
53▶ t.Errorf("Zero lines expected got %d", fileJob.Lines)
54 }
55
· · ·
60 CountStats(&fileJob)
61 if fileJob.Lines != 1 {
62▶ t.Errorf("One line expected got %d", fileJob.Lines)
63 }
64
+ 126 more matches in this file
23
24// ReadFile actually reads the file into a buffer size controlled by LargeByteCount
25▶func (reader *FileReader) ReadFile(path string, size int) ([]byte, error) {
26 fd, err := os.Open(path)
27 if err != nil {
· · ·
28▶ return nil, fmt.Errorf("error opening %s: %v", path, err)
29 }
30 defer func(file *os.File) {
· · ·
48 _, err = io.Copy(reader.Buffer, fd)
49 if err != nil {
50▶ return nil, fmt.Errorf("error reading %s: %v", path, err)
51 }
52
29}
30
31▶func runSCC(args ...string) (string, error) {
32 args = slices.Insert(args, 0, sccTestFlag)
33 cmd := exec.Command(sccBinPath, args...)
· · ·
265 }
266 if !strings.Contains(output, "MATLAB") {
267▶ t.Errorf("can not find MATLAB, output: %s", output)
268 }
269 if !strings.Contains(output, "Objective C") {
· · ·
270▶ t.Errorf("can not find Objective C, output:\n%s", output)
271 }
272}
· · ·
276 output, err := runSCC("--not-a-real-option")
277 if err == nil {
278▶ t.Fatal("scc should exit with error code")
279 }
280 if !strings.Contains(output, "Error: unknown flag: --not-a-real-option") {
· · ·
280▶ if !strings.Contains(output, "Error: unknown flag: --not-a-real-option") {
281 t.Fatalf("scc should report invalid options, output:\n%s", output)
282 }
+ 23 more matches in this file
18
19 if !strings.Contains(str.String(), "Estimated Schedule Effort (organic) 0.22 months") {
20▶ t.Error("expected to match got", str.String())
21 }
22}
· · ·
27
28 if !strings.Contains(str.String(), "Processed 1 bytes, 0.000 megabytes (SI)") {
29▶ t.Error("expected to match got", str.String())
30 }
31}
· · ·
36
37 if !strings.Contains(str.String(), "Processed 1000000 bytes, 1.000 megabytes (SI)") {
38▶ t.Error("expected to match got", str.String())
39 }
40}
· · ·
95
96 if summary.Files[0].Filename != "aaaa.go" {
97▶ t.Error("Sorting on lines failed", val)
98 }
99 }
· · ·
105
106 if summary.Files[0].Filename != "aaaa.go" {
107▶ t.Error("Sorting on blank failed", val)
108 }
109 }
+ 93 more matches in this file
14
15 if ext != "css" {
16▶ t.Error("Expected css got", ext)
17 }
18 AllowListExtensions = []string{}
· · ·
25
26 if x != "" || y == nil {
27▶ t.Error("Expected no match got", x)
28 }
29}
· · ·
48
49 if x != "Perl" || y != nil {
50▶ t.Error("Expected Perl match got", x, "for", c)
51 }
52 }
· · ·
65
66 if x != "PHP" || y != nil {
67▶ t.Error("Expected PHP match got", x)
68 }
69 }
· · ·
83
84 if x != "Python" || y != nil {
85▶ t.Error("Expected Python match got", x)
86 }
87 }
+ 31 more matches in this file
11 got := LocomoComplexityDensity(10, 0)
12 if got != 0 {
13▶ t.Errorf("Expected 0 for zero code lines, got %f", got)
14 }
15}
· · ·
18 got := LocomoComplexityDensity(30, 100)
19 if math.Abs(got-0.3) > 0.001 {
20▶ t.Errorf("Expected 0.3, got %f", got)
21 }
22}
· · ·
26 got := LocomoComplexityFactor(0.3, 5)
27 if got < 3.7 || got > 3.8 {
28▶ t.Errorf("Expected ~3.74, got %f", got)
29 }
30}
· · ·
34 got := LocomoComplexityFactor(0.05, 5)
35 if got < 2.0 || got > 2.2 {
36▶ t.Errorf("Expected ~2.12, got %f", got)
37 }
38}
· · ·
42 got := LocomoIterationFactor(0.3, 1.5, 2)
43 if got < 2.5 || got > 2.7 {
44▶ t.Errorf("Expected ~2.60, got %f", got)
45 }
46}
+ 23 more matches in this 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}
+ 14 more matches in this file
36
37 if fileJob.Lines != 14 {
38▶ t.Errorf("Expected 14 lines got %d", fileJob.Lines)
39 }
40
· · ·
41 if fileJob.Code != 11 {
42▶ t.Errorf("Expected 11 lines got %d", fileJob.Code)
43 }
44
· · ·
45 if fileJob.Comment != 2 {
46▶ t.Errorf("Expected 2 lines got %d", fileJob.Comment)
47 }
48
· · ·
49 if fileJob.Blank != 1 {
50▶ t.Errorf("Expected 1 lines got %d", fileJob.Blank)
51 }
52}
· · ·
65
66 if fileJob.Lines != 3 {
67▶ t.Errorf("Expected 3 lines")
68 }
69
+ 20 more matches in this file
40
41 if fileJob.Lines != 23 {
42▶ t.Errorf("Expected 23 lines")
43 }
44
· · ·
45 if fileJob.Code != 16 {
46▶ t.Errorf("Expected 16 lines got %d", fileJob.Code)
47 }
48
· · ·
49 if fileJob.Comment != 4 {
50▶ t.Errorf("Expected 4 lines got %d", fileJob.Comment)
51 }
52
· · ·
53 if fileJob.Blank != 3 {
54▶ t.Errorf("Expected 3 lines got %d", fileJob.Blank)
55 }
56}
· · ·
82
83 if fileJob.Lines != 15 {
84▶ t.Errorf("Expected 15 lines got %d", fileJob.Lines)
85 }
86
+ 15 more matches in this file
13
14 if len(ExtensionToLanguage) == 0 {
15▶ t.Error("Should not be 0")
16 }
17
· · ·
18 if len(LanguageFeatures) == 0 {
19▶ t.Error("Should not be 0")
20 }
21}
· · ·
26
27 if PathDenyList[0] != "testing" {
28▶ t.Error("expected / to be trimmed")
29 }
30
· · ·
39 ConfigureLazy(true)
40 if !isLazy {
41▶ t.Error("isLazy should be true")
42 }
43
· · ·
44 ConfigureLazy(false)
45 if isLazy {
46▶ t.Error("isLazy should be false")
47 }
48}
+ 8 more matches in this file
9func TestTraceLevel(t *testing.T) {
10 if levelTrace.String() != "TRACE" {
11▶ t.Errorf("traceLevel format error: got %s, want TRACE", levelTrace.String())
12 }
13 if levelDebug.String() != "DEBUG" {
· · ·
14▶ t.Errorf("traceLevel format error: got %s, want DEBUG", levelDebug.String())
15 }
16 if levelWarn.String() != "WARN" {
· · ·
17▶ t.Errorf("traceLevel format error: got %s, want WARN", levelWarn.String())
18 }
19 if levelError.String() != "ERROR" {
· · ·
19▶ if levelError.String() != "ERROR" {
20 t.Errorf("traceLevel format error: got %s, want ERROR", levelError.String())
21 }
· · ·
20▶ t.Errorf("traceLevel format error: got %s, want ERROR", levelError.String())
21 }
22 if traceLevel(0).String() != "" {
+ 10 more matches in this file
19
20 if !c.Check(1, []byte("hash")) {
21▶ t.Error("Expected match")
22 }
23
· · ·
24 if !c.Check(1, []byte("hash2")) {
25▶ t.Error("Expected match")
26 }
27
· · ·
28 if c.Check(2, []byte("hash")) {
29▶ t.Error("Expected no match")
30 }
31
· · ·
32 if c.Check(1, []byte("hash3")) {
33▶ t.Error("Expected no match")
34 }
35}
· · ·
87 typ, depth, closed := trie.Match(tc.token)
88 if typ != tc.expectType {
89▶ t.Errorf("\"%v\" matched wrong type, want: %v, got: %v", string(tc.token), tc.expectType, typ)
90 }
91 if depth != tc.expectDepth {
+ 6 more matches in this 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 })
13 // Should be around 582
14 if got < 580 || got > 585 {
15▶ t.Errorf("Got %f", got)
16 }
17}
· · ·
23 // Should be around 2602096
24 if got < 2602000 || got > 2602100 {
25▶ t.Errorf("Got %f", got)
26 }
27}
· · ·
33 // Should be around 2.7
34 if got < 2.6 || got > 2.8 {
35▶ t.Errorf("Got %f", got)
36 }
37}
107 result := StringSimilarRatio(tc.s1, tc.s2) >= SimilarStringThreshold
108 if result != tc.isSimilar {
109▶ t.Errorf("StringSimilarRatio(%q, %q) failed, got %v, want %v", tc.s1, tc.s2, result, tc.isSimilar)
110 }
111 }
· · ·
113
114func TestGetMostSimilarFlags(t *testing.T) {
115▶ flags := pflag.NewFlagSet("testing", pflag.ExitOnError)
116 _ = flags.Bool("no-ignore", false, "test")
117 _ = flags.Bool("no-gitignore", false, "test")
· · ·
171 result := GetMostSimilarFlags(flags, tc.name)
172 if !slices.Equal(result, tc.expects) {
173▶ t.Errorf("got: %v, want: %v", result, tc.expects)
174 }
175 }