git-time-metric / gtm

Simple, seamless, lightweight time tracking for Git
MIT License
973 stars 52 forks source link

Panic in event.pathFromSource when doing record on quoted path ending with backslash #106

Open idbrii opened 4 years ago

idbrii commented 4 years ago

In short: doing gtm record "c:\Users\" causes a panic.


I'm using gtm-vim and vim-dirvish. gtm-vim had a bug git-time-metric/gtm-vim-plugin#6 that made it try to run gtm record on directories. vim-dirvish lets you edit directories, so gtm-vim tried to record them.

I added output to gtm-vim to see why gtm kept saying it wasn't available:

patch:
     if v:shell_error
       echoerr s:no_gtm_err
+      echom output
     else

And here's the output I get

 panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x64d57e]

goroutine 1 [running]:
github.com/git-time-metric/gtm/event.pathFromSource(0xc04208e000, 0x45, 0xc042079c30, 0x4e8a7e, 0xc04209a180, 0x6d0200, 0x0, 0x0)
    c:/gopath/src/github.com/git-time-metric/gtm/event/event.go:19 +0xde
github.com/git-time-metric/gtm/event.Record(0xc04208e000, 0x45, 0x1, 0x2)
    c:/gopath/src/github.com/git-time-metric/gtm/event/manager.go:20 +0x40
github.com/git-time-metric/gtm/command.RecordCmd.Run(0x951500, 0xc0420b0320, 0x0, 0xc04205a0e0, 0x1, 0x2, 0x0)
    c:/gopath/src/github.com/git-time-metric/gtm/command/record.go:100 +0x295
github.com/git-time-metric/gtm/command.(*RecordCmd).Run(0xc042058cc0, 0xc04205a0e0, 0x1, 0x2, 0xc042052860)
    <autogenerated>:1 +0x73
github.com/mitchellh/cli.(*CLI).Run(0xc042060500, 0xc042096c60, 0x70efa1, 0x5)
    c:/gopath/src/github.com/mitchellh/cli/cli.go:255 +0x1f2
main.main()
    c:/gopath/src/github.com/git-time-metr

I'm using gtm.exe from gtm.v1.3.5.windows.tar.gz, git-time-metric/gtm-vim-plugin@ebd33f7d01a7ac9b2695f71b1136d6b89a0d5d44, and gvim 8.2.1076.

This is the specific command that gtm-vim was trying to run:

:echo system('gtm record "C:\david\settings\daveconfig\multi\vim\bundle\git-time-metric\plugin\"')

C:\settings\daveconfig is a git repo and C:\david\settings\daveconfig\multi\vim\bundle\git-time-metric is a submodule.

I get a panic 100% of the time when I run that command or with any path with a trailing \.

" fine
:echo system('gtm record "C:\david"')
" fine
:! gtm record C:\david\
" panic
:echo system('gtm record "C:\david\"')
" panic
:! gtm record "C:\david\"

Or panic from a command prompt:

> gtm record "c:\david\"