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

Add an optional third parameter to redisget() to specify a default value #207

Closed
wants to merge 1 commit into from

Conversation

ghoneycutt
Copy link
Member

No description provided.

@ghoneycutt
Copy link
Member Author

@petems I got the acceptance tests this time :)

@petems
Copy link
Member

petems commented May 18, 2017

@ghoneycutt Awesome stuff! 😄

I might ask you to rebase as I was doing some work to update the function docs to work with puppet-strings (see #208), but overall looks good

@ghoneycutt
Copy link
Member Author

No problem, I'll rebase once #208 gets merged.

Copy link
Member

@petems petems left a comment

Choose a reason for hiding this comment

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

Just a little refactoring around the core defaulting logic

raise(Puppet::ParseError, "redisget(): Wrong argument type given (#{key.class} for String) for arg1 (key)") if key.is_a?(String) == false
raise(Puppet::ParseError, "redisget(): Wrong argument type given (#{url.class} for String) for arg2 (url)") if url.is_a?(String) == false

begin
Copy link
Member

Choose a reason for hiding this comment

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

This logic looks a little confusing to me, could we clean this up somehow?

Copy link
Member

Choose a reason for hiding this comment

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

Possibly something like changing k to returned_value? And is there a way to break out the nesting? Not sure if there's something better it just looks a little confusing IMO

Copy link
Member Author

Choose a reason for hiding this comment

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

changed the variable name and added the exception message to the output as requested

else
k
end
rescue
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to pick which error to rescue from here?

Copy link
Member

@petems petems May 18, 2017

Choose a reason for hiding this comment

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

Something like

rescue Exception => e
      if default
        debug "Connection to redis failed with #{e}"
        default
      else
        raise(Puppet::Error, "Connection to redis server failed - #{e}")
      end
    end

Gives a little more detail for both the happy and sad paths

@petems
Copy link
Member

petems commented May 19, 2017

Merged in #209

@petems petems closed this May 19, 2017
@ghoneycutt ghoneycutt deleted the redisget_default branch May 19, 2017 14:16
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