Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetInt should return default val instead of panic #75

Closed
FarmerChillax opened this issue Apr 30, 2024 · 2 comments · Fixed by #77
Closed

GetInt should return default val instead of panic #75

FarmerChillax opened this issue Apr 30, 2024 · 2 comments · Fixed by #77
Milestone

Comments

@FarmerChillax
Copy link

In GetInt function should return default value instead of panic

// GetInt parses the expanded value as an int if the key exists.
// If key does not exist or the value cannot be parsed the default
// value is returned. If the value does not fit into an int the
// function panics with an out of range error.
func (p *Properties) GetInt(key string, def int) int {
	v, err := p.getInt64(key)
	if err != nil {
		return def
	}
	return intRangeCheck(key, v)
}

more:

panic(fmt.Sprintf("Value %d for key %s out of range", v, key))

@magiconair
Copy link
Owner

magiconair commented Dec 7, 2024

I agree, however that would also be a breaking change. I think what is missing are the GetInt32 and GetUint32 methods which don't panic. We should also add a GetFloat32 method for completeness. Can you submit a PR?

@magiconair
Copy link
Owner

I'll create a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants