wakatime / wakatime-cli

Command line interface used by all WakaTime text editor plugins
https://wakatime.com/plugins
BSD 3-Clause "New" or "Revised" License
277 stars 41 forks source link

Fix deps parser for c++ files #1013

Closed gandarez closed 8 months ago

gandarez commented 8 months ago

This PR adds a new dependency parser for c++ to avoid panicking by replacing c parser.

runtime error: index out of range [32] with length 32

goroutine 1 [running]:
runtime/debug.Stack()
 C:/hostedtoolcache/windows/go/1.21.5/x64/src/runtime/debug/stack.go:24 +0x5e
github.com/wakatime/wakatime-cli/cmd.runCmd.func1()
 D:/a/wakatime-cli/wakatime-cli/cmd/run.go:313 +0x13c
panic({0x1579bc0?, 0xc0004a0120?})
 C:/hostedtoolcache/windows/go/1.21.5/x64/src/runtime/panic.go:914 +0x21f
github.com/dlclark/regexp2.(*runner).popcrawl(...)
 C:/Users/runneradmin/go/pkg/mod/github.com/dlclark/regexp2@v1.10.0/runner.go:937
github.com/dlclark/regexp2.(*runner).uncapture(...)
 C:/Users/runneradmin/go/pkg/mod/github.com/dlclark/regexp2@v1.10.0/runner.go:1466
github.com/dlclark/regexp2.(*runner).execute(0xc0003f4000)
 C:/Users/runneradmin/go/pkg/mod/github.com/dlclark/regexp2@v1.10.0/runner.go:264 +0x37ed
github.com/dlclark/regexp2.(*runner).scan(0xc0003f4000, {0xc000700000?, 0xc0000d9630?, 0xe98de8?}, 0x14d4ca0?, 0x0, 0x13?)
 C:/Users/runneradmin/go/pkg/mod/github.com/dlclark/regexp2@v1.10.0/runner.go:143 +0x2b8
github.com/dlclark/regexp2.(*Regexp).run(0xc000440f80, 0x78?, 0x6372, {0xc000700000, 0x7bf4, 0x8000})
 C:/Users/runneradmin/go/pkg/mod/github.com/dlclark/regexp2@v1.10.0/runner.go:90 +0xef
github.com/dlclark/regexp2.(*Regexp).FindRunesMatchStartingAt(...)
 C:/Users/runneradmin/go/pkg/mod/github.com/dlclark/regexp2@v1.10.0/regexp.go:201
github.com/alecthomas/chroma/v2.matchRules({0xc000700000, 0x7bf4, 0x8000}, 0x6372, {0xc00065c200, 0x1f, 0xeec477?})
 C:/Users/runneradmin/go/pkg/mod/github.com/gandarez/chroma/v2@v2.9.1-wakatime.1/regexp.go:452 +0xc5
github.com/alecthomas/chroma/v2.(*LexerState).Iterator(0xc000000480)
 C:/Users/runneradmin/go/pkg/mod/github.com/gandarez/chroma/v2@v2.9.1-wakatime.1/regexp.go:212 +0x225
github.com/alecthomas/chroma/v2.Iterator.Tokens(0xc000400120)
 C:/Users/runneradmin/go/pkg/mod/github.com/gandarez/chroma/v2@v2.9.1-wakatime.1/iterator.go:15 +0x46
github.com/wakatime/wakatime-cli/pkg/deps.(*ParserC).Parse(0xc0001dc360, {0xc00029e100, 0x34})
 D:/a/wakatime-cli/wakatime-cli/pkg/deps/c.go:67 +0x259
github.com/wakatime/wakatime-cli/pkg/deps.Detect({0xc00029e100, 0x34}, 0x0?)
 D:/a/wakatime-cli/wakatime-cli/pkg/deps/deps.go:127 +0x3c8
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func8.1({0xc0004ac8c0, 0x1, 0x1})
 D:/a/wakatime-cli/wakatime-cli/pkg/deps/deps.go:68 +0x29b
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func7.1({0xc0004ac8c0, 0x1, 0x1})
 D:/a/wakatime-cli/wakatime-cli/pkg/language/language.go:54 +0x355
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func6.1({0xc0004ac8c0, 0x1, 0x1})
 D:/a/wakatime-cli/wakatime-cli/pkg/filestats/filestats.go:72 +0x55a
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithReplacing.func5.1({0xc0004ac8c0, 0x1, 0x1})
 D:/a/wakatime-cli/wakatime-cli/pkg/apikey/apikey.go:42 +0x1ab
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func4.1({0xc0004ac780, 0x1, 0x0?})
 D:/a/wakatime-cli/wakatime-cli/pkg/remote/remote.go:111 +0x93c
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithFiltering.func3.1({0xc0000c3a40, 0x1, 0x1?})
 D:/a/wakatime-cli/wakatime-cli/pkg/filter/filter.go:41 +0x2d0
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithEntityModifier.func2.1({0xc0000c3a40, 0x1, 0x1})
 D:/a/wakatime-cli/wakatime-cli/pkg/heartbeat/entity_modify.go:24 +0x1ea
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithFormatting.func1.1({0xc0000c3a40, 0x1, 0x1})
 D:/a/wakatime-cli/wakatime-cli/pkg/heartbeat/format.go:32 +0x28e
github.com/wakatime/wakatime-cli/cmd/heartbeat.SendHeartbeats.NewHandle.func4({0xc0000c3a40, 0x1, 0x1})
 D:/a/wakatime-cli/wakatime-cli/pkg/heartbeat/heartbeat.go:163 +0xc8
github.com/wakatime/wakatime-cli/cmd/heartbeat.SendHeartbeats(0xc0003d4540, {0xc00048c460, 0x1c})
 D:/a/wakatime-cli/wakatime-cli/cmd/heartbeat/heartbeat.go:129 +0x7c5
github.com/wakatime/wakatime-cli/cmd/heartbeat.Run(0x1884380?)
 D:/a/wakatime-cli/wakatime-cli/cmd/heartbeat/heartbeat.go:37 +0xbd
github.com/wakatime/wakatime-cli/cmd.runCmd(0xc0003d4540, 0x0, 0x0, 0x17a7c08)
 D:/a/wakatime-cli/wakatime-cli/cmd/run.go:331 +0x124
github.com/wakatime/wakatime-cli/cmd.RunCmdWithOfflineSync(0xc0001b4560?, 0xde?, 0x40?, 0x0?, 0x17a7be0)
 D:/a/wakatime-cli/wakatime-cli/cmd/run.go:281 +0x25
github.com/wakatime/wakatime-cli/cmd.Run(0x0?, 0x0?)
 D:/a/wakatime-cli/wakatime-cli/cmd/run.go:137 +0x72d
github.com/wakatime/wakatime-cli/cmd.NewRootCMD.func1(0xc00004bb00?, {0x15b2231?, 0x4?, 0x15b2235?})
 D:/a/wakatime-cli/wakatime-cli/cmd/root.go:29 +0x17
github.com/spf13/cobra.(*Command).execute(0xc000004300, {0xc00004a110, 0xf, 0xf})
 C:/Users/runneradmin/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:944 +0x863
github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
 C:/Users/runneradmin/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
 C:/Users/runneradmin/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
github.com/wakatime/wakatime-cli/cmd.Execute()
 D:/a/wakatime-cli/wakatime-cli/cmd/root.go:271 +0x18
main.main()
 D:/a/wakatime-cli/wakatime-cli/main.go:6 +0xf
codecov-commenter commented 8 months ago

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (80c37fd) 62.92% compared to head (a62f7ec) 62.95%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

@@             Coverage Diff             @@
##           develop    #1013      +/-   ##
===========================================
+ Coverage    62.92%   62.95%   +0.02%     
===========================================
  Files          372      373       +1     
  Lines        15890    15957      +67     
===========================================
+ Hits          9999    10045      +46     
- Misses        5364     5378      +14     
- Partials       527      534       +7     
Flag Coverage Δ
unittests 62.95% <69.11%> (+0.02%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
pkg/deps/c.go 67.69% <ø> (ø)
pkg/deps/deps.go 87.37% <100.00%> (+0.24%) :arrow_up:
pkg/deps/cpp.go 67.69% <67.69%> (ø)