yeqown / go-qrcode

To help gophers generate QR Codes with customized styles, such as color, block size, block shape, and icon.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when not adding an option

nurmanhabib opened this issue · comments

My code

qrc, err := qrcode.New("https://github.com/yeqown/go-qrcode")
if err != nil {
    fmt.Printf("could not generate QRCode: %v", err)
}

// save file
if err := qrc.Save("tes.jpg"); err != nil {
    fmt.Printf("could not save image: %v", err)
}

Error

=== RUN   TestQRCodePDF_CreateQRCode
--- FAIL: TestQRCodePDF_CreateQRCode (0.02s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x12de60e]

goroutine 6 [running]:
testing.tRunner.func1.1(0x1474ca0, 0x18ae4a0)
	/usr/local/go/src/testing/testing.go:940 +0x2f5
testing.tRunner.func1(0xc00011b680)
	/usr/local/go/src/testing/testing.go:943 +0x3f9
panic(0x1474ca0, 0x18ae4a0)
	/usr/local/go/src/runtime/panic.go:969 +0x166
github.com/yeqown/go-qrcode.drawAndSave(0x159b760, 0xc0000105c0, 0xc0001dbc00, 0x21, 0x21, 0x21, 0x21, 0xc000066780, 0x14eb532, 0xc00004fe68)
	/Users/nurmanhabib/go/pkg/mod/github.com/yeqown/go-qrcode@v1.5.0/image.go:43 +0x7e
github.com/yeqown/go-qrcode.(*QRCode).SaveTo(0xc00018c0c0, 0x159b760, 0xc0000105c0, 0x159b760, 0xc0000105c0)
	/Users/nurmanhabib/go/pkg/mod/github.com/yeqown/go-qrcode@v1.5.0/qrcode.go:621 +0xa4
github.com/yeqown/go-qrcode.(*QRCode).Save(0xc00018c0c0, 0x14eb532, 0x7, 0x0, 0x0)
	/Users/nurmanhabib/go/pkg/mod/github.com/yeqown/go-qrcode@v1.5.0/qrcode.go:612 +0x15b
xxx/watermark_test.TestQRCodePDF_CreateQRCode(0xc00011b680)
	/Users/nurmanhabib/x/watermark/qrcode_pdf_test.go:32 +0xec
testing.tRunner(0xc00011b680, 0x15167c8)
	/usr/local/go/src/testing/testing.go:991 +0xdc
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1042 +0x357

Process finished with exit code 1

Temporary solution (add at least one option)


qrc, err := qrcode.New("https://github.com/yeqown/go-qrcode", qrcode.WithBuiltinImageEncoder(qrcode.PNG_FORMAT))

there should be a default option so that there is no fatal error

thanks for your feedback, default option will be used ~

@nurmanhabib v1.5.1 6efc0b3 fixed this issue