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

(PUP-5741) Fix confusing errors when comparing values #4597

Merged
merged 1 commit into from
Jan 27, 2016

Conversation

thallgren
Copy link
Contributor

Prior to this commit, the method MessageData#label had two functions.
If called with an argument, it presented the String form for that
argument. If called without, it returned a ModelLabelProvider. This
made it impossible to produce a message for nil.

This commit splits the method in two. One providermethod that takes
no arguments and just returns the ModuleLabelProvider and one that
always returns the String representation of its argument. All calls
are adjusted accordingly.

@@ -130,7 +135,7 @@ def self.hard_issue(issue_code, *args, &block)
# @todo configuration
#
NAME_WITH_HYPHEN = issue :NAME_WITH_HYPHEN, :name do
"#{label.a_an_uc(semantic)} may not have a name containing a hyphen. The name '#{name}' is not legal"
"#{provider.a_an_uc(semantic)} may not have a name containing a hyphen. The name '#{name}' is not legal"
Copy link
Contributor

Choose a reason for hiding this comment

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

We could just make a_an, a_an_uc, the, and the_uc available directly. Here that would be:

"#{a_an_uc(semantic)} may not have a name containing a hyphen. The name '#{name}' is not legal"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but that's not within scope for this PR IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

The "provider.a_an_uc" does not read nicely, hence my suggestion to get rid of it completely. I think that is acceptable to do within the scope of this ticket. It is a very small additional change.

@thallgren thallgren closed this Jan 26, 2016
@thallgren thallgren force-pushed the issue/pup-5741/confusing-errors branch from fbc00be to 622bc7f Compare January 26, 2016 21:16
@thallgren thallgren reopened this Jan 26, 2016
@@ -58,7 +58,8 @@ def format(hash ={})
# in the issue's message producing block.
# @api private
#
class MessageData
class MessageData < Puppet::Pops::LabelProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, so that is a quick way of getting the methods. But it is not right :-)
This class is not allowed to have those methods itself as it is language agnostic. It is the label provider's job to do that. We happen to have an english provider that has a base implementation for all different kinds of english label providers.

The support should be implemented as delegation to the label provider that is referencing.

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. this class must have the mehods, and they must then call the same method on the provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

The I18N implementation is only embryonic so hard to guess this from just looking at the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can do a method missing, and delegate to the provider if it is set, and it it responds to the missing method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding delegation. Delegating will not make a future I18N transition easier because the methods themselves are wrong. a_an, a_an_uc for instance, is hardly applicable in, say Swedish. We would need others though, to differentiate 'en', 'ett' etc. Hence, all issues and the label provider must be rewritten.

The only way to make it simpler is to retain my previous attempt for this PR and go via provider.a_an in the actual text of the message since that's the place where things must change.

Copy link
Contributor

Choose a reason for hiding this comment

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

After discussion we decided to change the label method instead so it takes *args. That fixes the actual problem and leaves the rest alone.

The method MessageData#label has two functions. If called with an
argument, it presents the String form for that argument. If called
without, it returned a `ModelLabelProvider`. Unfortunately, it decided
whether or not it got an argument by testing if it's value was `nil`
(the default). This made it impossible to produce a message for the
argument `nil`.

This commit changes the parameter so that it uses the splat operator
and can check the actual number of passed arguments.
@thallgren thallgren force-pushed the issue/pup-5741/confusing-errors branch from 9789174 to f343cce Compare January 26, 2016 23:03
hlindberg added a commit that referenced this pull request Jan 27, 2016
@hlindberg hlindberg merged commit aa7e45f into puppetlabs:3.x Jan 27, 2016
@thallgren thallgren deleted the issue/pup-5741/confusing-errors branch February 8, 2016 15:59
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 this pull request may close these issues.

2 participants