Skip Menu |

This queue is for tickets about the WWW-Salesforce CPAN distribution.

Report information
The Basics
Id: 46091
Status: resolved
Priority: 0/
Queue: WWW-Salesforce

People
Owner: cwhitener [...] gmail.com
Requestors: MARKSTOS [...] cpan.org
rsniff [...] amllc.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)

Attachments


Subject: Suggested changes to the API
Date: Thu, 14 May 2009 16:20:50 -0600
To: <bug-WWW-Salesforce [...] rt.cpan.org>
From: "Reggie Sniff" <rsniff [...] amllc.com>
I am using the API and it works wonderfully with a few exceptions. Unfortunately, I have had to pretty much copy your code and make changes to support my needs. The problems I have, and I assume others might have is that from within most parts of the code, whenever you get an error, you use "carp $err" and then you return 0 or you attempt to use 'carp($res->faultstring())'. Both of these are problematic for different reasons. In the first, I only have access to the error if I have access to STDERR. It would be much better if it was returned or stored in some global hash. The second also causes problems if the $res object fails to get instantiated. When this happens, if you try to call $res->faultstring() on a non-existent reference, the code dies. When $res fails to get a reference it actually returns a scalar (error message) rather then the ref object you are expecting. To use an example, what I have done is this: Instead of this code: ------------ if ( !defined $table_name || !length $table_name ) { carp( 'Param1 of get_field_list() should be a string' ); return 0; } my $res = $self->describeSObject( 'type' => $table_name ); if ( $res->fault() ) { carp( $res->faultstring() ); return 0; } ----------------- I use this -t allows me to have access to the error (and email it back to muyself) without having to look through a log file: ------------ if ( !defined $table_name || !length $table_name ) { # I am returning the error so that I can handle it. I just need to check the ref() of the returned value first return ( 'Param1 of get_field_list() should be a string' ); } my $res = $sforce->describeSObject( 'type' => $table_name ); # If the above fails the $res object is a scalar error message unless (ref($res)) { return $res; } # This should never be reached if $res is not a proper reference if ( $res->fault() ) { return ( $res->faultstring() ); } ------------ Regards, Reggie Sniff
Reggie, I think this is a nonissue. Carp raises an exception like any other, which you can catch with an eval block (not string eval, see perldoc -f eval).
This is an issue that should be addressed much like other modules in the CPAN, ie DBI. WWW::Salesforce::errstr will contain the last error from here on out. Sorry, it will take me a while to dedicate some time to this. I will try to get this done as soon as possible. my $sforce = WWW::Salesforce->login( ... ) or croak( $WWW::Salesforce::errstr ); and so forth.
On Tue Jul 07 10:45:52 2009, IANK wrote: Show quoted text
> Reggie, I think this is a nonissue. Carp raises an exception like any > other, which you can > catch with an eval block (not string eval, see perldoc -f eval). > >
I've gone and confused carp with croak. Please disregard
Subject: no exception handling is provided
Methods such as "create()" can fail and throw exceptions. If I dump the undocumented data structure returned by create(), I can see it's trying to tell me this: "sObject type \'Idea\' is not supported. If y ou are attempting to use a custom object, be sure to append the \'__c\' after the entity name. Ple ase reference your WSDL or the describe call for the appropriate names." However, there is no way to access this information through the WWW::Salesforce API.
Hi Reggie, Sorry it's taken so long, but my time is extremely limited. This pre-alpha is the direction I'm going to be heading for the next release. Please take a look and see if you have any suggestions about improvements or other comments. NOTE: This is nowhere near done and hardly any of the methods are available yet. But before I get too far, I want someone else to look at it and see if what I think is a logical direction to steer into is in fact logical. Please read the documentation provided as a lot of things have changed. Thanks, Chase
Download WWW-Salesforce-0.200_1.tar.gz
application/x-gzip 13.6k

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #46091] Suggested changes to the API
Date: Mon, 21 Sep 2009 09:23:54 -0600
To: <bug-WWW-Salesforce [...] rt.cpan.org>
From: "Reggie Sniff" <rsniff [...] amllc.com>
Hi Chase, This looks better, with the use of the $self->{errstr}variable. A couple of suggestions: 1) I think the $self->{errstr}should always be used anytime you have an error which will result in a return code. For example, it should always be set with the error code prior to calling the 'confess' function (and perhaps call 'carp' rather than 'confess').. 2) The only other thing needed is a method to access the $self->{errstr} variable. The way I implement it is that if there is an error return code, we should be able to retrieve the error code and handle it as we see fit rather than having to use an eval and have to deal with a 'die' (via the confess). Regards, Reggie Show quoted text
----- Original Message ----- From: "Chase Whitener via RT" <bug-WWW-Salesforce@rt.cpan.org> To: <rsniff@amllc.com> Sent: Friday, September 18, 2009 8:19 AM Subject: [rt.cpan.org #46091] Suggested changes to the API
> <URL: https://rt.cpan.org/Ticket/Display.html?id=46091 > > > Hi Reggie, > > Sorry it's taken so long, but my time is extremely limited. This > pre-alpha is the direction I'm going to be heading for the next release. > Please take a look and see if you have any suggestions about > improvements or other comments. > > NOTE: This is nowhere near done and hardly any of the methods are > available yet. But before I get too far, I want someone else to look at > it and see if what I think is a logical direction to steer into is in > fact logical. > > Please read the documentation provided as a lot of things have changed. > > Thanks, > Chase >
Hi Reggie, errstr() is a function that allows the caller to get the last error message on the object. my $sforce = WWW::Salesforce->new(); die $sforce->errstr() unless ( $sforce->login( username=>'foo',password=>'bar') ); This is being documented more heavily as we speak. As for the confess() calls. Those will only happen on errors that are not recoverable. In this version, they're being used a bit more than I like, but I'm getting general ideas working rather than perfect code at the moment. Thanks, Chase
Subject: Re: [rt.cpan.org #46091] no exception handling is provided
Date: Mon, 21 Sep 2009 11:04:16 -0600
To: <bug-WWW-Salesforce [...] rt.cpan.org>, <MARKSTOS [...] cpan.org>
From: "Reggie Sniff" <rsniff [...] amllc.com>
Hi Chase, Sorry, didn't notice the note about the errstr() method. I think the new use of the errstr() is great and I applaud you for the code, in general. It is great to have such helpful code available On another note ... I also meant to note that I found some memory leaks in the Simple.pm code, specifically in the do_query method. It was killing my system to do queries with 2000 records (severe memory usage) and eventually ate up all my server memory and caused it to hang, requireing reboot. I found it best to reduce the record limit to 500 to keep it manageable. I found that if I did an undef of the $res variable after each use, it significantly limited my memory usage and seemed to stop the unbound memory growth. To make do the fix, I did an 'undef $res' right before the line in do_query() "while ( $done eq 'false' ) {" and then another undef $res at the end of the while loop. I also had to set up a fixed variable as not to lose the reference information so I added a line 'my @data = $res->valueof( '//queryMoreResponse/result/records' );' and then used the @data in the 'push'. I also did a little rearranging (see below) and set up a loop to delete the empty hash keys (to save more memory) before pushing them on the @rows array. --------------- snippet from original do_query() ------------------- while ( $done eq 'false' ) { $res = $self->queryMore( queryLocator => $ql, limit => $limit ); if ( $res->fault() ) { carp( $res->faultstring() ); return 0; } $done = $res->valueof( '//queryMoreResponse/result/done' ); $ql = $res->valueof( '//queryMoreResponse/result/queryLocator' ); push @rows, $res->valueof( '//queryMoreResponse/result/records' ) if ( $res->valueof( '//queryMoreResponse/result/size' ) ); } ------------------------------------ ----------------------- updated do_query() - reduces memory usage ----------- undef $res; while ( $done eq 'false' ) { $res = $sforce->queryMore( queryLocator => $ql, limit => $limit ); if ( $res->fault() ) { return( $res->faultstring() ); } $done = $res->valueof( '//queryMoreResponse/result/done' ); $ql = $res->valueof( '//queryMoreResponse/result/queryLocator' ); if ( $res->valueof( '//queryMoreResponse/result/size' )) { my @data = $res->valueof( '//queryMoreResponse/result/records' ); $cnt += @data; $self->{'log'}->log("do_query: records process = $cnt"); # Not really necessary but im my case I just deleted the empty hash keys in order to # save more memory foreach my $row (@data) { foreach my $key ( keys %{$row} ) { ###print "\nDeleting $key => $row->{$key}" if ($row->{$key} eq '' ); delete $row->{$key} if ( $row->{$key} eq '' ); } } push @rows, @data; # Clean up? undef $res; } } ---------------------------------- Show quoted text
----- Original Message ----- From: "Chase Whitener via RT" <bug-WWW-Salesforce@rt.cpan.org> To: <MARKSTOS@cpan.org>; <rsniff@amllc.com> Sent: Monday, September 21, 2009 10:37 AM Subject: [rt.cpan.org #46091] no exception handling is provided
> <URL: https://rt.cpan.org/Ticket/Display.html?id=46091 > > > Hi Reggie, > > errstr() is a function that allows the caller to get the last error > message on the object. > > my $sforce = WWW::Salesforce->new(); > die $sforce->errstr() > unless ( $sforce->login( username=>'foo',password=>'bar') ); > > This is being documented more heavily as we speak. As for the confess() > calls. Those will only happen on errors that are not recoverable. In > this version, they're being used a bit more than I like, but I'm getting > general ideas working rather than perfect code at the moment. > > Thanks, > Chase > >
Resolved with release 0.12. Carp and return has been replaced with die and an error string.