Presenting a custom error message if source file in module does not exist

33 views
Skip to first unread message

Craig Barr

unread,
Aug 2, 2014, 1:55:01 AM8/2/14
to puppe...@googlegroups.com
This feels like a beginner question so apologies to the experts out there reading this. Please skip to the last line of this post for the 'shortened version of this question'.

For my module, I believe there is a high likelihood the user may not copy a required source file to the module 'files' directory before applying the module. In this use case, we cannot version control the source file with the module due to constraints. As such, I would like to present a custom error message that clearly explains to the user what they need to do (e.g. You must download file X from Y and ensure it is copied to Z before doing a puppet run.)

I know that without this custom error message puppet will automatically throw an error when we try to first use the file. That said, I don't believe in this particular case the error message will be user friendly enough as it would look something like this:
 
Error: /Stage[main]/Mymodule::Install/File[/tmp/mydestinationfile.txt]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/mymodule/mysourcefile.txt

To an experienced puppet user this makes perfect sense but to a puppet novice they may initially scratch their head wondering where puppet:///modules/mymodule/mysourcefile.txt would be on the file system.

I tried a few things but where I came unstuck was on how to assert against a file in the convention puppet:///modules/mymodule/mysourcefile.txt since this is not a native file representation.

TL;DR How do I output a custom error message for a failed assertion that a source file exists. In other words, how do I display a nice error message when puppet:///modules/mymodule/mysourcefile.txt does not exist

Felix Frank

unread,
Aug 4, 2014, 8:21:45 AM8/4/14
to puppe...@googlegroups.com
On 08/02/2014 07:55 AM, Craig Barr wrote:
> TL;DR How do I output a custom error message for a failed assertion that
> a source file exists. In other words, how do I display a nice error
> message when puppet:///modules/mymodule/mysourcefile.txt does not exist

Hi,

this feels like more of a puppet-users kind of question, yes?

Sorry, I have no feedback beyond that.

Thanks,
Felix

David Schmitt

unread,
Aug 4, 2014, 8:46:22 AM8/4/14
to puppe...@googlegroups.com
On 2014-08-02 07:55, Craig Barr wrote:
> TL;DR How do I output a custom error message for a failed assertion that
> a source file exists. In other words, how do I display a nice error
> message when puppet:///modules/mymodule/mysourcefile.txt does not exist

A great way to improve the situation would be to improve puppet to
enumerate the locations it searched in the filesystem (perhaps only in
the server log, to avoid leaking sensitive information) and file a
jira-ticket + pull request.

If you only need it for a Very Special Case[tm], then you might be
served by doing a special fail_unless_exists() function that you deliver
with your module.


Regards, David
--
* Always looking for people I can help with awesome projects *
G+: https://plus.google.com/+DavidSchmitt
Blog: http://club.black.co.at/log/
LinkedIn: http://at.linkedin.com/in/davidschmitt
Reply all
Reply to author
Forward
0 new messages