-
Notifications
You must be signed in to change notification settings - Fork 931
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
Config: Don't panic and forward errors #13465
Conversation
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
return nil, err | ||
} | ||
|
||
if count > 1 && voters < int(maxVoters) { |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
return err | ||
} | ||
|
||
err = s.BGP.Reconfigure(address, uint32(asn), net.ParseIP(routerid)) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
node.Role = db.RaftVoter | ||
} else if standbys < int(state.GlobalConfig.MaxStandBy()) { | ||
} else if standbys < int(maxStandBy) { |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
roles := &app.RolesChanges{ | ||
Config: app.RolesConfig{ | ||
Voters: int(state.GlobalConfig.MaxVoters()), | ||
StandBys: int(state.GlobalConfig.MaxStandBy()), | ||
Voters: int(maxVoters), |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Voters: int(state.GlobalConfig.MaxVoters()), | ||
StandBys: int(state.GlobalConfig.MaxStandBy()), | ||
Voters: int(maxVoters), | ||
StandBys: int(maxStandBy), |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
@roosterfish please can you explain further what has changed to require this now, or has the panic scenario always existed? |
It has always existed, just saw it as part of the other story with the hidden passwords. |
Please could you give an example, i do not follow. |
Let's take the func (c *Config) HTTPSAllowedCredentials() bool {
return c.m.GetBool("core.https_allowed_credentials")
} Removing the func (c *Config) HTTPSAllowedCredentials() (bool, error) {
return c.m.GetBool("core.https_allowed_credentials")
} For example right now if the value of I am wondering, if instead of causing a panic, we should rather forward the potential error message instead. This is what is currently proposed in the PR. The problematic piece is for the server config we have to move the setting stored as string back to their original data type (bool, int) which can cause an error by nature. |
Do we even need the Config struct anymore? Can we use a map everywhere like we do with the others and use shared.FalseOrEmpty etc |
It would also allow resolving the different behaviors of defaults compared to rest of system |
That would be another option yes. For the |
Should this be closed or rebasee now? |
I have it on the radar. But as the underlying structure is now again a |
Shall we close or rebase? |
Closing for now. |
This removes several
panic()
calls from thelxd/config
package when trying to read configuration and instead forward the errors.As the changes feel quite invasive now I am wondering if a better approach would be to instead perform the validation when setting the respective value. A read operation would then just return a valid value. This would also be in line with what we do for storage driver configuration (there we just read from
map[string]string
).Any thoughts?