|
7 | 7 | use IO::File; |
8 | 8 | use Digest::MD5; |
9 | 9 | use Data::Dumper; |
10 | | - |
| 10 | +use Scalar::Util qw( blessed ); |
| 11 | +use Exception::Class ( |
| 12 | + 'EDAMTest::Exception::ExceptionWrapper', |
| 13 | + 'EDAMTest::Exception::FileIOError', |
| 14 | +); |
| 15 | + |
| 16 | +use LWP::Protocol::https; # it is not needed to 'use' here, but it must be installed. |
| 17 | + # if it is not installed, an error (Thrift::TException object) is to be thrown. |
11 | 18 | use Thrift::HttpClient; |
12 | 19 | use Thrift::BinaryProtocol; |
13 | 20 | use EDAMTypes::Types; # you must do `use' EDAMTypes::Types and EDAMErrors::Types |
|
30 | 37 | } |
31 | 38 |
|
32 | 39 | eval { |
| 40 | + # any exception occured in this eval block is Exception::Class::Base object. |
| 41 | + # if other is thrown, it is to be wrapped in EDAMTest::Exception::ExceptionWrapper. |
| 42 | + local $SIG{__DIE__} = sub { |
| 43 | + my ( $err ) = @_; |
| 44 | + if ( not ( blessed $err && $err->isa('Exception::Class::Base') ) ) { |
| 45 | + EDAMTest::Exception::ExceptionWrapper->throw( error => $err ); |
| 46 | + } |
| 47 | + }; |
| 48 | + |
33 | 49 | my $evernote_host = 'sandbox.evernote.com'; |
34 | 50 | my $user_store_url = 'https://' . $evernote_host . '/edam/user'; |
35 | 51 |
|
|
82 | 98 | #/ include attributes such as filename and location. |
83 | 99 | my $filename = $FindBin::Bin . "/enlogo.png"; |
84 | 100 | my $image_bin = do { |
85 | | - my $iof = IO::File->new( $filename, '<' ) or die 'file open failed'; |
| 101 | + my $iof = IO::File->new( $filename, '<' ) |
| 102 | + or EDAMTest::Exception::FileIOError->throw( "file open failed: $filename" ); |
86 | 103 | $iof->binmode( ':bytes' ); |
87 | 104 | do { local $/; <$iof> }; |
88 | 105 | }; |
|
122 | 139 |
|
123 | 140 | printf "Successfully created a new note with GUID: %s\n", $created_note->guid; |
124 | 141 | }; |
125 | | -if ( $@ ) { |
126 | | - warn 'ERROR'; |
127 | | - warn Dumper $@; |
| 142 | +if ( my $err = $@ ) { |
| 143 | + print STDERR "[ERROR]\n"; |
| 144 | + if ( blessed $err->error ) { |
| 145 | + print STDERR "=== Error object ===\n"; |
| 146 | + local $Data::Dumper::Indent = 1; |
| 147 | + print STDERR Dumper( $err->error ); |
| 148 | + } else { |
| 149 | + print STDERR "=== Error message ===\n"; |
| 150 | + print STDERR $err->error, "\n"; |
| 151 | + } |
| 152 | + print STDERR "=== Stack trace ===\n"; |
| 153 | + print STDERR $err->trace->as_string; |
| 154 | + exit 1; |
128 | 155 | } |
0 commit comments