<Derek.Whayman@barclayscapital.com>
2007-May-11 15:24 UTC
Exception handling in custom facts
Hi. I''d like to use exception handling in my custom facts. For example, in plain Ruby: begin buildno = '''' bcrelease = open("/etc/BCrelease") while (line = bcrelease.gets) line = line.chomp buildno = $1 if line =~ /^Build:\s+(\d+)/ end bcrelease.close print "#{buildno}\n" rescue print "No file?\n" end Works fine. However, in a custom fact the rescue clause doesn''t quite do it for me: Facter.add("buildno") do setcode do begin buildno = '''' bcrelease = open("/etc/BCrelease") while (line = bcrelease.gets) line = line.chomp buildno = $1 if line =~ /^Build:\s+(\d+)/ end bcrelease.close buildno rescue print "XXX: No such file?\n" '''' end end end # puppetd -tov --noop --test info: Loading fact buildno XXX: No such file? err: No such file or directory - /etc/BCrelease So we -_do_ get the exception handled, however Puppet aborts anyway :-( The err: line is the contents of $! How do I persuade facter that it''s not an error to abort on? Best regards, Derek ------------------------------------------------------------------------ For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ------------------------------------------------------------------------
On May 11, 2007, at 10:24 AM, <Derek.Whayman@barclayscapital.com> <Derek.Whayman@barclayscapital.com> wrote: [...]> # puppetd -tov --noop --test > info: Loading fact buildno > XXX: No such file? > err: No such file or directory - /etc/BCrelease > > So we -_do_ get the exception handled, however Puppet aborts > anyway :-( > > The err: line is the contents of $! > > How do I persuade facter that it''s not an error to abort on?Umm, this is news to me. I just tried it locally: Facter.add("failure") do setcode do begin File.open("/no/such/file") do |f| f.read end rescue => detail "" end end end It seems to behave correctly -- I get no result back -- but I''m using this from Facter, not within Puppet. Either way, though, Facter shouldn''t have any idea that an exception was caught, and I wouldn''t expect I could figure get the behaviour you''re seeing even if I wanted to. In other words, I''m pretty confused. -- If two men agree on everything, you may be sure that one of them is doing the thinking. -- Lyndon B. Johnson --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
<Derek.Whayman@barclayscapital.com>
2007-May-14 08:16 UTC
Re: Exception handling in custom facts
Well it was a Friday afternoon. This is working for me now - with my original code?!? Blech. Derek -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of Luke Kanies Sent: 11 May 2007 17:55 To: Puppet User Discussion Subject: Re: [Puppet-users] Exception handling in custom facts On May 11, 2007, at 10:24 AM, <Derek.Whayman@barclayscapital.com> <Derek.Whayman@barclayscapital.com> wrote: [...]> # puppetd -tov --noop --test > info: Loading fact buildno > XXX: No such file? > err: No such file or directory - /etc/BCrelease > > So we -_do_ get the exception handled, however Puppet aborts anyway > :-( > > The err: line is the contents of $! > > How do I persuade facter that it''s not an error to abort on?Umm, this is news to me. I just tried it locally: Facter.add("failure") do setcode do begin File.open("/no/such/file") do |f| f.read end rescue => detail "" end end end It seems to behave correctly -- I get no result back -- but I''m using this from Facter, not within Puppet. Either way, though, Facter shouldn''t have any idea that an exception was caught, and I wouldn''t expect I could figure get the behaviour you''re seeing even if I wanted to. In other words, I''m pretty confused. -- If two men agree on everything, you may be sure that one of them is doing the thinking. -- Lyndon B. Johnson --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users ------------------------------------------------------------------------ For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ------------------------------------------------------------------------
On May 14, 2007, at 3:16 AM, <Derek.Whayman@barclayscapital.com> wrote:> Well it was a Friday afternoon. This is working for me now - with my > original code?!?I hate that, but at least it''s working. :/ -- If a `religion'' is defined to be a system of ideas that contains unprovable statements, then Godel taught us that mathematics is not only a religion, it is the only religion that can prove itself to be one. -- John Barrow --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com