wakatime / wakatime-cli

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

Try to fix panic on remote detection #1114

Closed gandarez closed 3 weeks ago

gandarez commented 3 weeks ago

This PR does some cleanups and removes unecessary calls in order to avoid panic. The line number 63 seems to be wrong in the call stack and it might happen in Go when there are defer usages as per this issue.

runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
runtime/debug.Stack()
/opt/hostedtoolcache/go/1.22.5/x64/src/runtime/debug/stack.go:24 +0x5e
github.com/wakatime/wakatime-cli/cmd.runCmd.func1()
/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:297 +0x148
panic({0xa89ca0?, 0x1251d70?})
/opt/hostedtoolcache/go/1.22.5/x64/src/runtime/panic.go:770 +0x132
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func4.1({0xc0004aa280, 0x1, 0x0?})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/remote/remote.go:63 +0x180
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithFiltering.func3.1({0xc0004bf400, 0x1, 0x4c5c9b?})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/filter/filter.go:41 +0x2d0
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithEntityModifier.func2.1({0xc0004bf400, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/heartbeat/entity_modify.go:28 +0x302
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithFormatting.func1.1({0xc0004bf400, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/heartbeat/format.go:32 +0x28e
github.com/wakatime/wakatime-cli/cmd/heartbeat.SendHeartbeats.NewHandle.func4({0xc0004bf400, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/heartbeat/heartbeat.go:175 +0xc8
github.com/wakatime/wakatime-cli/cmd/heartbeat.SendHeartbeats(0xc000007880, {0xc000038d50, 0x2a})
/home/runner/work/wakatime-cli/wakatime-cli/cmd/heartbeat/heartbeat.go:140 +0x850
github.com/wakatime/wakatime-cli/cmd/heartbeat.Run(0xc000007880)
/home/runner/work/wakatime-cli/wakatime-cli/cmd/heartbeat/heartbeat.go:39 +0xc5
github.com/wakatime/wakatime-cli/cmd.runCmd(0xc000007880, 0x0, 0x0, 0xd3d8f0)
/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:315 +0x127
github.com/wakatime/wakatime-cli/cmd.RunCmdWithOfflineSync(0xc000007880, 0x0, 0x0, 0x0?)
/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:272 +0x25
github.com/wakatime/wakatime-cli/cmd.RunE(0xc000016308, 0xc000007880)
/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:135 +0x945
github.com/wakatime/wakatime-cli/cmd.NewRootCMD.func1(0xc0001ad800?, {0xb35a60?, 0x4?, 0xb35a64?})
/home/runner/work/wakatime-cli/wakatime-cli/cmd/root.go:32 +0x17
github.com/spf13/cobra.(*Command).execute(0xc000016308, {0xc000134010, 0xe, 0xe})
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940 +0x882
github.com/spf13/cobra.(*Command).ExecuteC(0xc000016308)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
github.com/wakatime/wakatime-cli/cmd.Execute()
/home/runner/work/wakatime-cli/wakatime-cli/cmd/root.go:301 +0x18
main.main()
/home/runner/work/wakatime-cli/wakatime-cli/main.go:6 +0xf
codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.

Project coverage is 63.11%. Comparing base (8153a4b) to head (28c5482). Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
pkg/remote/remote.go 54.54% 5 Missing :warning:
@@           Coverage Diff            @@
##           develop    #1114   +/-   ##
========================================
  Coverage    63.10%   63.11%           
========================================
  Files          383      383           
  Lines        16570    16561    -9     
========================================
- Hits         10457    10452    -5     
+ Misses        5543     5540    -3     
+ Partials       570      569    -1     
Flag Coverage Δ
unittests 63.11% <54.54%> (+<0.01%) :arrow_up:

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

Files with missing lines Coverage Δ
pkg/remote/remote.go 64.85% <54.54%> (+0.22%) :arrow_up: