Skip to content

Conversation

luke-jr
Copy link
Member

@luke-jr luke-jr commented Mar 5, 2022

Currently, Number values can cause GetArg/ GetBoolArg to throw an exception, which most of the code isn't expecting (eg #24457).

AFAIK it isn't possible to normally get Numbers in settings right now, but that's expected to change with #15936 (which could create downgrading issues without this fixed), and in any case it isn't a great idea to randomly crash because of a logically-value settings.json value anyway.

This doesn't fix Get*Arg from throwing in the case it encounters an Array or Object. It's not obvious how to handle those scenarios. However, the functions touched are refactored to explicitly clarify that those scenarios will throw.

NOTE: Based on 0.20 branch-point, so a clean merge to everything newer. For testing, you will probably want to merge onto 23.x or master.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 3766c66

Agree with the concept and couldn't find any issues with the code.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 6, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@luke-jr
Copy link
Member Author

luke-jr commented Mar 9, 2022

Rebased due to merge of partial fix in #24498

@fanquake
Copy link
Member

The unit tests are failing:

test/getarg_tests.cpp(103): error: in "getarg_tests/setting_args": exception std::runtime_error expected but not raised
test/getarg_tests.cpp(104): error: in "getarg_tests/setting_args": exception std::runtime_error expected but not raised
test/getarg_tests.cpp(110): error: in "getarg_tests/setting_args": exception std::runtime_error expected but not raised
test/getarg_tests.cpp(111): error: in "getarg_tests/setting_args": exception std::runtime_error expected but not raised
test/getarg_tests.cpp(117): error: in "getarg_tests/setting_args": exception std::runtime_error expected but not raised
test/getarg_tests.cpp(118): error: in "getarg_tests/setting_args": exception std::runtime_error expected but not raised
test/getarg_tests.cpp(53): Leaving test case "setting_args"; testing time: 63184us

@fanquake fanquake requested a review from ryanofsky March 11, 2022 11:36
@luke-jr
Copy link
Member Author

luke-jr commented Mar 11, 2022

Fixed tests.

@luke-jr luke-jr force-pushed the bugfix_settings_numberval branch from bd32cd9 to 3372227 Compare March 11, 2022 20:24
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see people having different opinions about this change. Personally I wouldn't object to it, but I also don't think it is an improvement overall.

The PR has changed since it was opened, but now it is pretty simple. Right now, if a user edits their settings.json file, or if the settings.json file gets corrupted some other way so it contains a numeric int or float value where a boolean value is expected, the current GetBoolArg method will throw an exception. This PR changes GetBoolArg behavior in that case to return false if the number is zero and true if the number is nonzero instead of throwing an exception.

Since this PR does not change behavior in other cases, GetBoolArg still throws exceptions if the settings value is an array or object, and GetBoolArg still has strange behavior for string values of returning true for the empty string "", true for strings which are non-zero decimal numbers, and false for all other strings.

Since this PR isn't removing every case where GetBoolArg throws exceptions, and since specifying a number where a boolean value is expected is a real indication of corruption or misconfiguration, I think throwing an exception is probably the best thing method can do right now to deal with whatever bad value is causing the problem. In longer run, if a change like #16545 goes through, settings could be typed, and errors could be triggered earlier on startup before an exception could happen here.

Anyway, this is not a very strong opinion, and I'm fine with other approaches.

Code review ACK 3372227

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@achow101
Copy link
Member

The PR didn't seem to attract much attention in the past. Also, the issue seems not important enough right now to keep it sitting around idle in the list of open PRs.

Closing due to lack of interest.

@achow101 achow101 closed this Sep 20, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Sep 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants