-
Notifications
You must be signed in to change notification settings - Fork 89
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
Fixed the Bosh::AzureCloud::Cloud.initialize
method's signature so …
#656
Conversation
…that the 2nd argument is optional. Note: Based on the changes made in commit #6c6ec5909b3635d5ea14a5f4dfa2263f2edf1468 (which added the 2nd argument), it seems that the argument was intended to be optional from the start. However, according to the method's signature, it was technically a required argument (despite that the method handles nil/missing values internally on line 29). Also, the following code already doesn't pass the 2nd argument: - https://github.com/cloudfoundry/bosh-azure-cpi-release/blob/9754cf84f18be7ce0250518bd5a660a459470b56/src/bosh_azure_cpi/bin/bosh_azure_console#L29 Note: The separate handling of the argument's default value on lines 26 and 29 are not redundant. The default value in the signature (line 26) only applies when the optional arg is omitted by the caller. If the caller explicitly specifies the argument with a value of `nil`, the arg default doesn't override the nil, but the `|| 1` on line 29 will. And without the argument default on line 26, the argument technically isn't optional, it is required. Meaning that it is technically an error for any caller to omit that argument, and that line 29 would therefore be covering up the caller's misuse of the method. So both "defaults" are needed in order to correctly handle all of the possible method invocation options for that argument. Here is the error message which was previously being detected (prior to this change): > Missing argument 'api_version'. Required 2, 'options, api_version'
I think we should not turn the second parameter as having any default value if it never had, and without any requirement for it. We should also not use any silent defaults that fix mis-use of the code, and also not implement unnecessary defensive measures. So, just conform to the let-it-crash principle. Let's keep it simple, please only remove the |
…pass the api_version argument, as requested by @bgandon here: cloudfoundry#656 (comment)
…rinciple, as requested by @bgandon here: cloudfoundry#656 (comment)
@bgandon I've revised the PR as you requested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay 😅, I think that's a bit overkill amount of code for the severity of the initial concern to be honest, but I appreciate the tenacity of your commitment in making it right 👍
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks! @Justin-W |
Just for context, this PR has broken some behavior. See f1f495c for more details. |
…that the 2nd argument is optional.
Note: Based on the changes made in commit 6c6ec59 (which added the 2nd argument), it seems that the argument was intended to be optional from the start. However, according to the method's signature, it was technically a required argument (despite that the method handles nil/missing values internally on line 29). Also, the following code already doesn't pass the 2nd argument:
bosh-azure-cpi-release/src/bosh_azure_cpi/bin/bosh_azure_console
Line 29 in 9754cf8
Note: The separate handling of the argument's default value on lines 26 and 29 are not redundant. The default value in the signature (line 26) only applies when the optional arg is omitted by the caller. If the caller explicitly specifies the argument with a value of
nil
, the arg default doesn't override the nil, but the|| 1
on line 29 will. And without the argument default on line 26, the argument technically isn't optional, it is required. Meaning that it is technically an error for any caller to omit that argument, and that line 29 would therefore be covering up the caller's misuse of the method. So both "defaults" are needed in order to correctly handle all of the possible method invocation options for that argument.Here is the error message which was previously being detected (prior to this change):
Checklist:
Please check each of the boxes below for which you have completed the corresponding task:
Please include below the summary portions of the output from the following 2 scripts:
NOTE: Please see how to setup dev environment and run unit tests in docs/development.md.
Unit Test output:
Rubocop output:
Changelog
Bosh::AzureCloud::Cloud.initialize
method's signature to make the 2nd positional argument explicitly optional