Skip to content

proposal: manage numbers with defined size and return an error if the value is out of range #30

@sbiemont

Description

@sbiemont

The current behavior does not correctly handle numbers with a fixed size (such as uint8 or int16)

Unmarshal should return an error in the same way it does for float32 and float64, which are correctly managed

Example of a case where a "value out of range" is not detected:

type whatever struct {
	Value uint8 `env:"VALUE_UINT8,required"` // Value in [0; 255]
}

os.Setenv("VALUE_UINT8", "300")

var w whatever
_, err := env.UnmarshalFromEnviron(&w)
if err != nil {
	panic(err)
}
fmt.Println("w:", w)
// Prints 300 mod 256 = 44
// w: {44}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions