# # Copyright (c) 2009-2010 NetApp Inc. # All rights reserved. # ## @summary Provide an exception class that is a subclass of ## NATE::BaseException that will be thrown when we're waiting on a job ## but it has already failed. ## ## @author madhavs@netapp.com, dl-nacl-dev@netapp.com ## @status Shared ## @pod here =head1 NAME NACL::Exceptions::JobFailed =head1 DESCRIPTION This exception gets thrown when a job we're waiting on (using any of wait_for_completion, wait_for_job or any of the wait_for_* routines provided by tasks) fails. =head1 ATTRIBUTES In addition to the attributes present in all exceptions derived from BaseException (text, stacktrace, etc), the following attributes are also present in execptions of type C: (note that each of the attributes have accessor methods, so the value can be obtained like: my $state = $exception->state(); ) =over =item state The final state of the job (Such as "Failure" or "Error") =item completion The completion string of the job (this describes the reason the job failed) =back =head1 EXAMPLE use NACL::Exceptions::JobFailed qw(:try); try { $aggr_stask_obj->wait_for_creation(); } catch NACL::Exceptions::JobFailed with { my $exception = $_[0]; # Accessing the error message is like all other exceptions $Log->comment("Error:\n" . $exception->text()); # Obtain the attributes specific to this exception $Log->comment("Final state of job was : " . $exception->state()); $Log->comment("Completion string of job was : " . $exception->completion()); }; =cut package NACL::Exceptions::JobFailed; use base qw(NATE::BaseException); use Class::MethodMaker [ scalar => 'state', scalar => 'completion' ]; use Params::Validate qw(:all); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); sub new { $Log->enter(); my ($pkg, $text, @args) = @_; my %opts = validate_with( params => \@args, spec => { state => { type => SCALAR }, completion => { type => SCALAR, optional => 1 }, }, allow_extra => 1 ); my $obj = $pkg->SUPER::new($text, %opts); $Log->exit(); return $obj; } 1;