ericlagergren / decimal

A high-performance, arbitrary-precision, floating-point decimal library.
https://godoc.org/github.com/ericlagergren/decimal
BSD 3-Clause "New" or "Revised" License
516 stars 61 forks source link

Json deconing throws nil dereference #141

Open eduardhasanaj opened 4 years ago

eduardhasanaj commented 4 years ago

Hi, I am seeing and error from this lib at this line github.com/ericlagergren/decimal@v0.0.0-20190912144844-2c3e3e1ef942/scan.go:43 +0x9e The error occurred when using json decoder on a model generated by sqlboiler.

ericlagergren commented 4 years ago

Could you post a code same that I could use to reproduce this? The panic on line 43 is ostensibly because the recover is nil, which is likely due to the generated code. I’m not familiar with sqlboiler.

eduardhasanaj commented 4 years ago

I am sorry for not providing the code.

type Option struct {
    ID           int               `boil:"id" json:"id" toml:"id" yaml:"id"`
    OptionlistID null.Int          `boil:"optionlist_id" json:"optionlist_id,omitempty" toml:"optionlist_id" yaml:"optionlist_id,omitempty"`
    Description  null.String       `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
    Price        types.NullDecimal `boil:"price" json:"price,omitempty" toml:"price" yaml:"price,omitempty"`

    R *optionR `boil:"-" json:"-" toml:"-" yaml:"-"`
    L optionL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

If I invoke scan on the Price before decoding I do not get the error. The problem is that I need this to decode an array

ericlagergren commented 4 years ago

Hm. Sounds similar to https://github.com/volatiletech/sqlboiler/issues/404. Perhaps I should revisit that issue.

aarondl commented 4 years ago

I've corrected this as ericlagergren suggested in his PR to sqlboiler. Will be in the dev branch for now and included in a later release.

jbactad commented 4 years ago

Hi @aarondl , do we have an update about this issue? If this is already fixed, do we know already when it will be merged?

eduardhasanaj commented 4 years ago

@jbactad Hi, Currently I am using dev branch for this problem.

aarondl commented 4 years ago

@jbactad As far as I'm concerned this is fixed already in master v3.6.0