Skip Menu |

This queue is for tickets about the REST-Neo4p CPAN distribution.

Report information
The Basics
Id: 80207
Status: resolved
Priority: 0/
Queue: REST-Neo4p

People
Owner: maj.fortinbras [...] gmail.com
Requestors: vertolet666 [...] yandex.ru
Cc:
AdminCc:

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



Subject: die after get_index_by_name
Date: Tue, 16 Oct 2012 10:46:55 +0400
To: bug-rest-neo4p [...] rt.cpan.org
From: DOBRO Sergei <vertolet666 [...] yandex.ru>
Hi,
 
 
But I noticed that if index does not exist, the program dies. Example:
 
use REST::Neo4p; 
REST::Neo4p->connect('http://127.0.0.1:7474');
my $idx = REST::Neo4p->get_index_by_name('my_index','node');
print "test\n";
 
OUTPUT:
Index 'my_index' not found in db
 
and word "test" is not printed.
 
Is there a better way to check the index? If id does not exist I would rather play with something like "return 404" than "die".
 
I'd like to write something like this:
 
my $idx = REST::Neo4p->get_index_by_name('my_index','node');
if ( INDEX_NOT_FOUND_CONDITION) {
      REST::Neo4p::Index->new('node', 'my_index');
      }
 
The same issue also concerns other methods ( get_node_by_id, get_relationship_by_id, etc.... )
 
Thanks.
Hi Sergei, Yes you can do this-- The modules use exceptions to report most errors. Exceptions die by default, but you can catch them and handle them using eval {}; So one way to do what you want is: use Exception::Class; my $idx; eval { $idx = REST::Neo4p->get_index_by_name('my_index','node'); }; my $e; if ( $e = Exception::Class->caught('REST::Neo4p::NotFoundException') ) { REST::Neo4p::Index->new('node','my_index'); } elsif ( $e = Exception::Class->caught() ) { ref $e ? $e->rethrow : die $e; } That's kind of complex, it's a lot like Java code. Maybe I will add a method like "index_exists" or "create_index_if_not_exists" to the next version. MAJ On Tue Oct 16 02:47:09 2012, vertolet666@yandex.ru wrote: Show quoted text
> Hi, Thanks for fixing that > https://rt.cpan.org/Public/Bug/Display.html?id=80196 > But I noticed that if index does not exist, the program dies. Example: > use > REST::Neo4p; REST::Neo4p->connect('http://127.0.0.1:7474');my $idx = > REST::Neo4p->get_index_by_name('my_index','node');print "test\n"; > OUTPUT:Index > 'my_index' not found in db and word "test" is not printed. Is there a > better > way to check the index? If id does not exist I would rather play with > something > like "return 404" than "die". I'd like to write something like this: > my $idx = > REST::Neo4p->get_index_by_name('my_index','node');if ( > INDEX_NOT_FOUND_CONDITION) { REST::Neo4p::Index->new('node', > 'my_index'); } The > same issue also concerns other methods ( get_node_by_id, > get_relationship_by_id, etc.... ) Thanks.
Subject: Re: [rt.cpan.org #80207] die after get_index_by_name
Date: Tue, 16 Oct 2012 18:05:59 +0400
To: "bug-REST-Neo4p [...] rt.cpan.org" <bug-rest-neo4p [...] rt.cpan.org>
From: DOBRO Sergei <vertolet666 [...] yandex.ru>
Hi Mark, "index_exists" would be quite enough :) Thanks! 16.10.2012, 16:44, "Mark Allen Jensen via RT" <bug-REST-Neo4p@rt.cpan.org>: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=80207 > > > Hi Sergei, > Yes you can do this-- The modules use exceptions to report most errors. > Exceptions die by default, but you can catch them and handle them using > eval {}; So one way to do what you want is: > > use Exception::Class; > my $idx; > eval { >  $idx = REST::Neo4p->get_index_by_name('my_index','node'); > }; > my $e; > if ( $e = Exception::Class->caught('REST::Neo4p::NotFoundException') ) { >   REST::Neo4p::Index->new('node','my_index'); > } > elsif ( $e = Exception::Class->caught() ) { >   ref $e ? $e->rethrow : die $e; > } > > That's kind of complex, it's a lot like Java code. Maybe I will add > a method like "index_exists" or "create_index_if_not_exists" to the > next version. > > MAJ > > On Tue Oct 16 02:47:09 2012, vertolet666@yandex.ru wrote: >
>>  Hi, Thanks for fixing that >>  https://rt.cpan.org/Public/Bug/Display.html?id=80196 >>  But I noticed that if index does not exist, the program dies. Example: >>  use >>  REST::Neo4p; REST::Neo4p->connect('http://127.0.0.1:7474');my $idx = >>  REST::Neo4p->get_index_by_name('my_index','node');print "test\n"; >>  OUTPUT:Index >>  'my_index' not found in db and word "test" is not printed. Is there a >>  better >>  way to check the index? If id does not exist I would rather play with >>  something >>  like "return 404" than "die". I'd like to write something like this: >>  my $idx = >>  REST::Neo4p->get_index_by_name('my_index','node');if ( >>  INDEX_NOT_FOUND_CONDITION) { REST::Neo4p::Index->new('node', >>  'my_index'); } The >>  same issue also concerns other methods ( get_node_by_id, >>  get_relationship_by_id, etc.... ) Thanks.
Resolving; considering index_exists() as a new feature request. Thanks! MAJ
Hi Sergei, What if get_index_by_name() just returned false if the index does not exist, but didn't die? That would be basically like "index_exists": my $idx = REST::Neo4p->get_index_by_name('fred'); unless ($idx) { $idx = REST::Neo4p::index->new('fred'); } Would that work for you ? thanks, Mark
Subject: Re: [rt.cpan.org #80207] die after get_index_by_name
Date: Sun, 18 Nov 2012 16:34:21 +0400
To: "bug-REST-Neo4p [...] rt.cpan.org" <bug-rest-neo4p [...] rt.cpan.org>
From: DOBRO Sergei <vertolet666 [...] yandex.ru>
Hi Mark,
 
it would be great! 
 
15.11.2012, 16:41, "Mark Allen Jensen via RT" <bug-REST-Neo4p@rt.cpan.org>:
Show quoted text

<URL: https://rt.cpan.org/Ticket/Display.html?id=80207 >

Hi Sergei,

What if get_index_by_name() just returned false if the index does not
exist, but didn't die? That would be basically like "index_exists":

my $idx = REST::Neo4p->get_index_by_name('fred');
unless ($idx) {
 $idx = REST::Neo4p::index->new('fred');
}

Would that work for you ?
thanks,
Mark

Hi Sergei-- I'm uploading 0.1285-- in this one, all these return a quiet false if the item is not found: REST::Neo4p::get_index_by_name() REST::Neo4p::get_node_by_id() REST::Neo4p::get_relationship_by_id() Hope this works for you- MAJ