Iwark / spreadsheet

Google Go (golang) library for reading and writing spreadsheet files on Google Docs.
MIT License
382 stars 53 forks source link

panic when creating a new spreadsheet #20

Closed adejoux closed 6 years ago

adejoux commented 6 years ago

Hello,

Thanks for your work.

I tested it with the code below but I have a crash when creating a new spreadsheet:

package main

import (
    "context"
    "io/ioutil"

    "github.com/Iwark/spreadsheet"
    "golang.org/x/oauth2/google"
)

func main() {
    data, err := ioutil.ReadFile("client_secret.json")
    checkError(err)
    conf, err := google.JWTConfigFromJSON(data, spreadsheet.Scope)
    checkError(err)
    client := conf.Client(context.TODO())
    service := spreadsheet.NewServiceWithClient(client)

    ss, err := service.CreateSpreadsheet(spreadsheet.Spreadsheet{
        Properties: spreadsheet.Properties{
            Title: "spreadsheet title",
        },
    })
    sheet, err := ss.SheetByIndex(0)
    service.ExpandSheet(sheet, 20, 10)
    row := 1
    column := 2
    sheet.Update(row, column, "hogehoge")
    sheet.Update(3, 2, "fugafuga")

    // Make sure call Synchronize to reflect the changes.
    err = sheet.Synchronize()
    checkError(err)
}

Here the error:

 go run main.go                                                                                                                                                                      
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x61625d]

goroutine 1 [running]:
github.com/Iwark/spreadsheet.(*Service).post(0x0, 0xc42017a0a0, 0x46, 0xc4200f5020, 0xc4200f5020, 0xc42017a0a0, 0x46, 0x32)
        /home/adejoux/devel/go/src/github.com/Iwark/spreadsheet/service.go:183 +0xdd
github.com/Iwark/spreadsheet.(*updateRequest).Do(0xc4200dfd38, 0xc42029c000, 0xc4200dfd48)
        /home/adejoux/devel/go/src/github.com/Iwark/spreadsheet/update_request.go:38 +0x2c2
github.com/Iwark/spreadsheet.(*Service).ExpandSheet(0xc4200dfef0, 0xc42029c000, 0x14, 0xa, 0x0, 0x0)
        /home/adejoux/devel/go/src/github.com/Iwark/spreadsheet/service.go:114 +0x1f5
main.main()
        /home/adejoux/devel/go/src/github.com/adejoux/go-user-list/main.go:25 +0x25f
exit status 2

Not sure if it's a bug or me doing a mistake. Thanks for help

Alain

Iwark commented 6 years ago

@adejoux Hi, thanks for reporting! I fixed the bug, please update the package and try it again!

adejoux commented 6 years ago

Hello.

Thanks. it's working now. :)