Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 70a4803

Browse files
committed
In sample code, error handling is changed (and LWP::Protocol::https installation check is added)
If LWP::Protocol::https is not installed, communication to evernote server via thrift is failed. Error message is not clear at the time, and so it is difficult to find the reason of that error. Therefore, the line 'use LWP::Protocol::https;' is added.
1 parent ea52b6a commit 70a4803

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

sample/client/EDAMTest.pl

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
use IO::File;
88
use Digest::MD5;
99
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.
1118
use Thrift::HttpClient;
1219
use Thrift::BinaryProtocol;
1320
use EDAMTypes::Types; # you must do `use' EDAMTypes::Types and EDAMErrors::Types
@@ -30,6 +37,15 @@
3037
}
3138

3239
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+
3349
my $evernote_host = 'sandbox.evernote.com';
3450
my $user_store_url = 'https://' . $evernote_host . '/edam/user';
3551

@@ -82,7 +98,8 @@
8298
#/ include attributes such as filename and location.
8399
my $filename = $FindBin::Bin . "/enlogo.png";
84100
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" );
86103
$iof->binmode( ':bytes' );
87104
do { local $/; <$iof> };
88105
};
@@ -122,7 +139,17 @@
122139

123140
printf "Successfully created a new note with GUID: %s\n", $created_note->guid;
124141
};
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;
128155
}

0 commit comments

Comments
 (0)