1,098 matches across 25 files for error
snippet_mode: auto · sorted by relevance
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/processor.go GO 14 matches · showing 5 view file →
344// Timeline selects an over-time view. With ByAuthor, runs the author
345// timeline report (plan 04); alone, runs the languages-over-time report
346// (plan 05). With Hotspots set, the combination errors out.
347var Timeline = false
348
· · ·
488 t := strings.Split(s, ":")
489 if len(t) != 2 {
490 printError(fmt.Sprintf("ignoring malformed count-as rule %q: expected format <from>:<to>", s))
491 continue
492 }
· · ·
508 // extension, so no mapping was registered. Warn rather than silently
509 // ignoring the rule, since count-as cannot mint new categories yet.
510 printError(fmt.Sprintf("ignoring count-as rule %q: target %q is not a known language or extension", s, t[1]))
511 }
512}
· · ·
546// Because regex patterns and paths legitimately contain ':', name and baselang
547// are peeled from the right and the pattern is whatever remains in between.
548func parseCountAsPattern(s string) (CountRule, error) {
549 engine := MatchGlob
550 rest := s
· · ·
562 lastColon := strings.LastIndex(rest, ":")
563 if lastColon == -1 {
564 return CountRule{}, fmt.Errorf("expected format [engine:]pattern:name:baselang")
565 }
566 baseLanguage := rest[lastColon+1:]
+ 9 more matches in this file
processor/report_render.go GO 12 matches · showing 5 view file →
77// existing default-named file (so a bare `--report` is non-destructive),
78// then collects data and renders the HTML output.
79func runReport(paths []string) error {
80 path := "."
81 if len(paths) > 0 {
· · ·
108// The io.Reader / io.Writer seam keeps the function unit-testable without
109// poking at os.Stdin / os.Stderr.
110func confirmReportOverwrite(outPath string, usedDefaultName, stdinIsTTY bool, in io.Reader, out io.Writer) error {
111 if !usedDefaultName {
112 return nil
· · ·
115 return nil
116 } else if err != nil {
117 // Some other stat error (permission?) — let the subsequent
118 // os.Create surface the underlying problem with a clearer
119 // "create report file: ..." wrapper instead of a stat error
· · ·
119 // "create report file: ..." wrapper instead of a stat error
120 // nobody asked for.
121 return nil
· · ·
122 }
123 if !stdinIsTTY {
124 return fmt.Errorf("%s already exists; rerun with --report=%s to overwrite explicitly", outPath, outPath)
125 }
126 _, _ = fmt.Fprintf(out, "%s already exists. Overwrite? [y/N]: ", outPath)
+ 7 more matches in this file
processor/report.go GO 8 matches · showing 5 view file →
253// scc's analysis modes (ULOC, line-length, per-file table) are gated by
254// process-wide globals. The report mode flips them on inside a single
255// invocation; we snapshot and restore via defer so panics, errors, or
256// in-process re-entrancy don't leak state into a later scc call.
257type reportFlagState struct {
· · ·
284// snapshotted and restored via defer, but callers should not assume the
285// flags retain their on-entry values during the call.
286func CollectReportData(path string) (ReportData, error) {
287 start := time.Now()
288
· · ·
439// rollup and a flat per-file slice. Reuses aggregateLanguageSummary by
440// feeding it the same FileJobs through a buffered channel.
441func walkAndAggregate(path string) ([]*FileJob, []LanguageSummary, Totals, error) {
442 if path == "" {
443 path = "."
· · ·
447 info, err := os.Stat(fpath)
448 if err != nil {
449 return nil, nil, Totals{}, fmt.Errorf("file or directory could not be read: %s", fpath)
450 }
451
· · ·
466 if len(dirPaths) > 0 {
467 fileWalker := gocodewalker.NewParallelFileWalker(dirPaths, potentialFilesQueue)
468 fileWalker.SetErrorHandler(func(e error) bool {
469 printError(e.Error())
470 return true
+ 3 more matches in this file
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/history_authors.go GO 6 matches · showing 5 view file →
368// walks history with baseline seeding, and writes the chosen format to
369// stdout or FileOutput.
370func runAuthorsReport(repoPath string) error {
371 observer := newHistoryAuthorsObserver()
372 if _, err := runHistory(repoPath, observer); err != nil {
· · ·
388}
389
390func renderAuthors(o *historyAuthorsObserver) (string, error) {
391 switch strings.ToLower(Format) {
392 case "", "tabular", "wide":
· · ·
397 return renderAuthorsJSON(o)
398 default:
399 return "", fmt.Errorf("unsupported --format %q for --by-author (supported: tabular, csv, json)", Format)
400 }
401}
· · ·
576}
577
578func renderAuthorsCSV(o *historyAuthorsObserver) (string, error) {
579 var sb strings.Builder
580 sb.WriteString(formatWindowComment(o.window))
· · ·
609 }
610 w.Flush()
611 if err := w.Error(); err != nil {
612 return "", err
613 }
+ 1 more matches in this file
mcp.go GO 12 matches · showing 5 view file →
112
113 errLogger := log.New(os.Stderr, "scc-mcp: ", log.LstdFlags)
114 if err := server.ServeStdio(mcpServer, server.WithErrorLogger(errLogger)); err != nil {
115 _, _ = fmt.Fprintf(os.Stderr, "scc-mcp: server error: %v\n", err)
116 os.Exit(1)
· · ·
115 _, _ = fmt.Fprintf(os.Stderr, "scc-mcp: server error: %v\n", err)
116 os.Exit(1)
117 }
· · ·
183}
184
185func mcpAnalyzeHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
186 args := request.GetArguments()
187
· · ·
195 absPath, err := filepath.Abs(path)
196 if err != nil {
197 return mcp.NewToolResultError(fmt.Sprintf("invalid path: %v", err)), nil
198 }
199
· · ·
200 // Verify path can be accessed
201 if _, err := os.Stat(absPath); err != nil {
202 return mcp.NewToolResultError(fmt.Sprintf("path cannot be accessed: %s: %v", absPath, err)), nil
203 }
204
+ 7 more matches in this file
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
processor/history_hotspots.go GO 8 matches · showing 5 view file →
25// the output (highest-scoring first); limit <= 0 returns every scored file.
26// HistoryDepth and the mailmap folding behave exactly as on the CLI path.
27func HotspotsJSONReport(repoPath string, limit int) (string, error) {
28 observer := newHotspotsObserver()
29 if _, err := runHistory(repoPath, observer); err != nil {
· · ·
36// --hotspots is set. Opens the repo at repoPath, walks history, and writes
37// the chosen format to stdout or FileOutput.
38func runHotspotsReport(repoPath string) error {
39 observer := newHotspotsObserver()
40 if _, err := runHistory(repoPath, observer); err != nil {
· · ·
222
223// renderHotspots returns the formatted output for the chosen --format.
224func renderHotspots(o *hotspotsObserver) (string, error) {
225 switch strings.ToLower(Format) {
226 case "", "tabular", "wide":
· · ·
231 return renderHotspotsJSON(o)
232 default:
233 return "", fmt.Errorf("unsupported --format %q for --hotspots (supported: tabular, csv, json)", Format)
234 }
235}
· · ·
315}
316
317func renderHotspotsCSV(o *hotspotsObserver) (string, error) {
318 var sb strings.Builder
319 sb.WriteString(formatWindowComment(o.window))
+ 3 more matches in this file
processor/history_author_timeline.go GO 6 matches · showing 5 view file →
186// when --by-author --timeline is set. Opens the repo, walks the window with
187// the configured bucket count, and writes the chosen format.
188func runAuthorTimelineReport(repoPath string) error {
189 observer := newHistoryAuthorTimelineObserver(HistoryBuckets)
190 if _, err := runHistory(repoPath, observer); err != nil {
· · ·
206}
207
208func renderAuthorTimeline(o *historyAuthorTimelineObserver) (string, error) {
209 switch strings.ToLower(Format) {
210 case "", "tabular", "wide":
· · ·
215 return renderAuthorTimelineJSON(o)
216 default:
217 return "", fmt.Errorf("unsupported --format %q for --by-author --timeline (supported: tabular, csv, json)", Format)
218 }
219}
· · ·
322}
323
324func renderAuthorTimelineCSV(o *historyAuthorTimelineObserver) (string, error) {
325 var sb strings.Builder
326 sb.WriteString(formatWindowComment(o.window))
· · ·
344 }
345 w.Flush()
346 if err := w.Error(); err != nil {
347 return "", err
348 }
+ 1 more matches in this file
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 }
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.Printf("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
processor/history_languages.go GO 6 matches · showing 5 view file →
188// walks the window with the configured bucket count, and writes the chosen
189// format.
190func runLanguagesTimelineReport(repoPath string) error {
191 observer := newHistoryLanguagesObserver(HistoryBuckets)
192 if _, err := runHistory(repoPath, observer); err != nil {
· · ·
208}
209
210func renderLanguagesTimeline(o *historyLanguagesObserver) (string, error) {
211 switch strings.ToLower(Format) {
212 case "", "tabular", "wide":
· · ·
217 return renderLanguagesTimelineJSON(o)
218 default:
219 return "", fmt.Errorf("unsupported --format %q for --timeline (supported: tabular, csv, json)", Format)
220 }
221}
· · ·
280}
281
282func renderLanguagesTimelineCSV(o *historyLanguagesObserver) (string, error) {
283 var sb strings.Builder
284 sb.WriteString(formatWindowComment(o.window))
· · ·
305 }
306 w.Flush()
307 if err := w.Error(); err != nil {
308 return "", err
309 }
+ 1 more matches in this file
scripts/include.go GO 12 matches · showing 5 view file →
36// compiled into this binary, which is the *old* constants.go (compiled before
37// this run rewrote it), so LANGUAGES.md always lagged the JSON by one pass.
38func loadLanguages() (map[string]processor.Language, error) {
39 files, _ := os.ReadDir(".")
40 langs := map[string]processor.Language{}
· · ·
44 file, err := os.Open(f.Name())
45 if err != nil {
46 return nil, fmt.Errorf("failed to open file '%s': %v", f.Name(), err)
47 }
48
· · ·
52 if err := json.NewDecoder(file).Decode(&data); err != nil {
53 _ = file.Close()
54 return nil, fmt.Errorf("failed to validate json in file '%s': %v", f.Name(), err)
55 }
56 _ = file.Close()
· · ·
61 for _, h := range lang.Heuristics {
62 if _, err := regexp.Compile(h.Pattern); err != nil {
63 return nil, fmt.Errorf("invalid heuristic regex %q for language '%s' in file '%s': %v", h.Pattern, name, f.Name(), err)
64 }
65 }
· · ·
74
75// encodes the language database as string literals in constants.go
76func generateConstants(langs map[string]processor.Language) error {
77 buf := &bytes.Buffer{}
78
+ 7 more matches in this file
processor/result.go GO 6 matches · showing 5 view file →
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.
18func 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 })
· · ·
79 excludePathRegexes = append(excludePathRegexes, regexpResult)
80 } else {
81 printError(err.Error())
82 }
83 }
+ 1 more matches in this file
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
processor/history_ignore.go GO 2 matches view file →
35// parses them, and produces a matcher. Respects the existing --no-ignore
36// (Ignore) and --no-scc-ignore (SccIgnore) flag globals.
37func buildHistoryIgnore(repo *git.Repository, head plumbing.Hash) (*historyIgnore, error) {
38 commit, err := repo.CommitObject(head)
39 if err != nil {
· · ·
46
47 var patterns []gitignore.Pattern
48 err = tree.Files().ForEach(func(f *object.File) error {
49 if f.Mode == filemode.Dir || f.Mode == filemode.Submodule || f.Mode == filemode.Symlink {
50 return nil
processor/history_validation.go GO 5 matches view file →
4
5import (
6 "errors"
7 "fmt"
8 "io"
· · ·
11
12// validateHistoryFlags checks the global flag state for the history reports
13// (--hotspots, --by-author, --timeline). Hard errors are returned and should
14// abort the run; recoverable conditions are written to warnDst as a single
15// line each and execution continues.
· · ·
16func validateHistoryFlags(warnDst io.Writer) error {
17 if !Hotspots && !ByAuthor && !Timeline {
18 return nil
· · ·
20
21 if HistoryDepth < 0 {
22 return errors.New("--depth must be >= 0 (0 means entire history)")
23 }
24
· · ·
25 if Timeline && HistoryBuckets < 1 {
26 return errors.New("--buckets must be >= 1")
27 }
28
processor/trace.go GO 9 matches · showing 5 view 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
94func printError(msg string) {
95 doPrint(os.Stderr, levelError, msg, nil)
96}
· · ·
95 doPrint(os.Stderr, levelError, msg, nil)
96}
97
+ 4 more matches in this file
processor/structs.go GO 2 matches view file →
156// unexported alias type carries the same field tags but none of the methods, so
157// marshaling it does not recurse.
158func (fileJob *FileJob) MarshalJSON() ([]byte, error) {
159 type alias FileJob
160 if Cognitive {
· · ·
223// mirroring FileJob.MarshalJSON: present (even at 0) when the metric is on,
224// omitted when off. See FileJob.MarshalJSON for the rationale.
225func (l LanguageSummary) MarshalJSON() ([]byte, error) {
226 type alias LanguageSummary
227 if Cognitive {
processor/workers_test.go GO 136 matches · showing 5 view file →
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
+ 131 more matches in this file
processor/filereader.go GO 3 matches view file →
23
24// ReadFile actually reads the file into a buffer size controlled by LargeByteCount
25func (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
packages/chocolatey/tools/chocolateyuninstall.ps1 POWERSHELL 1 matches view file →
11## If this is an exe, change fileType, silentArgs, and validExitCodes
12
13$ErrorActionPreference = 'Stop'; # stop on all errors
14$packageArgs = @{
15 packageName = $env:ChocolateyPackageName
processor/report_test.go GO 94 matches · showing 5 view file →
14)
15
16func writeTestFile(path, content string) error {
17 return os.WriteFile(path, []byte(content), 0o644)
18}
· · ·
37
38 if !data.GitAvailable {
39 t.Errorf("expected GitAvailable=true for fixture repo, got false")
40 }
41 if data.RepoName == "" {
· · ·
42 t.Errorf("expected RepoName to be derived from path, got empty")
43 }
44 if data.SccVersion == "" {
· · ·
45 t.Errorf("expected SccVersion to be set")
46 }
47 if data.GeneratedAt.IsZero() {
· · ·
48 t.Errorf("expected GeneratedAt to be set")
49 }
50
+ 89 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
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.