Panic on `v2` branch but not `master`
Opened this issue · 5 comments
When I import gopkg.in/Iwark/spreadsheet.v2
I get the following panic on service.ExpandSheet(...)
and sheet.Synchronize()
:
panic: runtime error: invalid memory address or nil pointer dereference
Everything works fine when I import github.com/Iwark/spreadsheet
Also wanted to say this has a very nice interface. I have it running nicely already!
Hi @grokify , thanks for your reporting!
Can you explain me more about the issue?
It works fine for me as follows:
package main
import (
"fmt"
spreadsheet "gopkg.in/Iwark/spreadsheet.v2"
)
func main() {
service, _ := spreadsheet.NewService()
spreadsheet, _ := service.FetchSpreadsheet("1mYiA2T4_QTFUkAXk0BE3u7snN2o5FgSRqxmRrn_Dzh4")
sheet, _ := spreadsheet.SheetByIndex(0)
sheet.Update(80, 11, "testtest")
service.ExpandSheet(sheet, 90, 12)
sheet.Synchronize()
}
If you have a simple code which get panic, it would be very helpful.
Thank you.
Hi,
Thanks for this great initiative. Makes a lot of sense.
I have the save issue explained above.
When I run the example code importing gopkg.in/Iwark/spreadsheet.v2 I get the same error (panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x12045d2]).
Fortunately everything runs fine when importing from Master branch/basically from github.com/Iwark/spreadsheet.
For the record, I followed a tutorial to properly get the credentials json (https://www.youtube.com/watch?v=cnPlKLEGR7E) and the sheet is not shared publicly.
To be more precise, the error is as follows :
goroutine 1 [running]: net/http.(*Client).deadline(0x0, 0x30, 0x30, 0x12b75c0) /usr/local/go/src/net/http/client.go:189 +0x22 net/http.(*Client).do(0x0, 0xc000118000, 0x0, 0x0, 0x0) /usr/local/go/src/net/http/client.go:585 +0x2ae net/http.(*Client).Do(...) /usr/local/go/src/net/http/client.go:567 net/http.(*Client).Post(0x0, 0xc00007a000, 0x66, 0x12fcb52, 0x10, 0x1360fc0, 0xc0004583c0, 0xc00013a040, 0xc00051da08, 0x100e458) /usr/local/go/src/net/http/client.go:827 +0x195 gopkg.in/Iwark/spreadsheet%2ev2.(*Service).post(0xc0000f9e58, 0xc00001e0a0, 0x46, 0xc000458180, 0xc000146868, 0xc00001e0a0, 0x46, 0x0) /Users/username/go/pkg/mod/gopkg.in/!iwark/spreadsheet.v2@v2.0.0-20191122095212-08231195c43b/service.go:278 +0x17a gopkg.in/Iwark/spreadsheet%2ev2.(*updateRequest).Do(0xc00051db90, 0xc000700400, 0xc00051db90) /Users/username/go/pkg/mod/gopkg.in/!iwark/spreadsheet.v2@v2.0.0-20191122095212-08231195c43b/update_request.go:38 +0x28e gopkg.in/Iwark/spreadsheet%2ev2.(*Service).SyncSheet(0xc0000f9e58, 0xc000700400, 0x5, 0x12fabaf) /Users/username/go/pkg/mod/gopkg.in/!iwark/spreadsheet.v2@v2.0.0-20191122095212-08231195c43b/service.go:206 +0x1c3 gopkg.in/Iwark/spreadsheet%2ev2.(*Sheet).Synchronize(...) /Users/username/go/pkg/mod/gopkg.in/!iwark/spreadsheet.v2@v2.0.0-20191122095212-08231195c43b/sheet.go:155 main.main() /Users/username/Documents/GolandProjects2020/local-file-hierarchy-compare/compare.go:34 +0x2fe exit status 2
And a last point, I use Go modules (go.mod) which is the recommended practice currently.
OK I believe the issue is due to the package name "spreadsheet" conflicting with the variable name in the example.
Variable 'spreadsheet' collides with imported package name
Indeed the example (Code example for Iwark/spreadsheet v2) begins to use the package name line 19 :
service := spreadsheet.NewServiceWithClient(client)
but then redefines the identifier spreadsheet
in the next line, line 20 :
spreadsheet, err := service.FetchSpreadsheet("1mYiA2T4_QTFUkAXk0BE3u7snN2o5FgSRqxmRrn_Dzh4")
For whatever reason it has an impact when using "gopkg.in/Iwark/spreadsheet.v2", whereas there is no impact when using "github.com/Iwark/spreadsheet".
In the end of the day the issue vanishes as soon as I change the variable name line 20.
I recommend you update the example code officially.