Re: [web2py] Re: REF: DAL Catching errors

2014-01-11 Thread Teddy Nyambe
Thanks exactly what I was looking for, will try it!
On 11 Jan 2014 19:00, "Anthony"  wrote:

> Good point. web2py normally does a rollback if a request results in an
> exception, but if you catch the exception, you would need to do the
> rollback yourself to prevent web2py from committing the transaction at the
> end of the request.
>
> Anthony
>
> On Saturday, January 11, 2014 11:48:08 AM UTC-5, Massimo Di Pierro wrote:
>>
>> Depending on the situation it may also be necessary to do:
>>
>> try:
>> 
>> except db._adapter.driver.IntegrityError as e:
>> db.rollback() # or db.commit()
>> return str(e)
>>
>>
>>
>>
>> On Saturday, 11 January 2014 09:17:33 UTC-6, Anthony wrote:
>>>
>>> It depends on how the particular exception class is implemented. In
>>> general, if you do str(error), you get the error message. I think in most
>>> exception classes, error.args[0] is also typically the error message. This
>>> is a general Python issue and not specific to web2py.
>>>
>>> try:
>>> 
>>> except db._adapter.driver.IntegrityError as e:
>>> return str(e)
>>>
>>> Anthony
>>>
>>> On Saturday, January 11, 2014 1:55:30 AM UTC-5, software.ted wrote:

 Hi Anthony!

 Those gems we need to know!!!, since i have to extract undocumented
 details on this list, I would like to find out how i can then get system
 generated messages cause there are many integrity error
 descriptions...instead of me having one message like this:

 try:
 ...
 except db._adapter.driver.IntegrityError:
 err_msg = "Duplicate record in database"

 I would like to have a situation were i can get system messages of the
 specific integrity error enountered:

 try:
 ...
 except db._adapter.driver.IntegrityError:
 err_msg = db.[some object].errorMessage


 Any pointers?


 On Sat, Jan 11, 2014 at 8:11 AM, Anthony  wrote:

> Another one of our great undocumented gems. :-)
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google
> Groups "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to web2py+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>



 --
 
 ...
 Teddy Lubasi Nyambe
 Opensource Zambia
 Lusaka, ZAMBIA

 Cell: +260 97 7760473
 website: http://www.opensource.org.zm

 ~/
 Human Knowledge belongs to the world! - AntiTrust

 Man is a tool-using animal. Without tools he is nothing, with tools he
 is all - Thomas Carlyle 1795-1881

 /~

>>>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-11 Thread Anthony
Good point. web2py normally does a rollback if a request results in an 
exception, but if you catch the exception, you would need to do the 
rollback yourself to prevent web2py from committing the transaction at the 
end of the request.

Anthony

On Saturday, January 11, 2014 11:48:08 AM UTC-5, Massimo Di Pierro wrote:
>
> Depending on the situation it may also be necessary to do:
>
> try:
> 
> except db._adapter.driver.IntegrityError as e:
> db.rollback() # or db.commit()
> return str(e)
>
>
>
>
> On Saturday, 11 January 2014 09:17:33 UTC-6, Anthony wrote:
>>
>> It depends on how the particular exception class is implemented. In 
>> general, if you do str(error), you get the error message. I think in most 
>> exception classes, error.args[0] is also typically the error message. This 
>> is a general Python issue and not specific to web2py.
>>
>> try:
>> 
>> except db._adapter.driver.IntegrityError as e:
>> return str(e)
>>
>> Anthony
>>
>> On Saturday, January 11, 2014 1:55:30 AM UTC-5, software.ted wrote:
>>>
>>> Hi Anthony!
>>>
>>> Those gems we need to know!!!, since i have to extract undocumented 
>>> details on this list, I would like to find out how i can then get system 
>>> generated messages cause there are many integrity error 
>>> descriptions...instead of me having one message like this:
>>>
>>> try:
>>> ...
>>> except db._adapter.driver.IntegrityError:
>>> err_msg = "Duplicate record in database"
>>>
>>> I would like to have a situation were i can get system messages of the 
>>> specific integrity error enountered:
>>>
>>> try:
>>> ...
>>> except db._adapter.driver.IntegrityError:
>>> err_msg = db.[some object].errorMessage
>>>
>>>
>>> Any pointers?
>>>
>>>
>>> On Sat, Jan 11, 2014 at 8:11 AM, Anthony  wrote:
>>>
 Another one of our great undocumented gems. :-)

 --
 Resources:
 - http://web2py.com
 - http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py (Source code)
 - https://code.google.com/p/web2py/issues/list (Report Issues)
 ---
 You received this message because you are subscribed to the Google 
 Groups "web2py-users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to web2py+un...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

>>>
>>>
>>>
>>> -- 
>>>
>>> ...
>>> Teddy Lubasi Nyambe
>>> Opensource Zambia
>>> Lusaka, ZAMBIA
>>>
>>> Cell: +260 97 7760473
>>> website: http://www.opensource.org.zm
>>>
>>> ~/
>>> Human Knowledge belongs to the world! - AntiTrust
>>>
>>> Man is a tool-using animal. Without tools he is nothing, with tools he 
>>> is all - Thomas Carlyle 1795-1881
>>>
>>> /~ 
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-11 Thread Massimo Di Pierro
Depending on the situation it may also be necessary to do:

try:

except db._adapter.driver.IntegrityError as e:
db.rollback() # or db.commit()
return str(e)




On Saturday, 11 January 2014 09:17:33 UTC-6, Anthony wrote:
>
> It depends on how the particular exception class is implemented. In 
> general, if you do str(error), you get the error message. I think in most 
> exception classes, error.args[0] is also typically the error message. This 
> is a general Python issue and not specific to web2py.
>
> try:
> 
> except db._adapter.driver.IntegrityError as e:
> return str(e)
>
> Anthony
>
> On Saturday, January 11, 2014 1:55:30 AM UTC-5, software.ted wrote:
>>
>> Hi Anthony!
>>
>> Those gems we need to know!!!, since i have to extract undocumented 
>> details on this list, I would like to find out how i can then get system 
>> generated messages cause there are many integrity error 
>> descriptions...instead of me having one message like this:
>>
>> try:
>> ...
>> except db._adapter.driver.IntegrityError:
>> err_msg = "Duplicate record in database"
>>
>> I would like to have a situation were i can get system messages of the 
>> specific integrity error enountered:
>>
>> try:
>> ...
>> except db._adapter.driver.IntegrityError:
>> err_msg = db.[some object].errorMessage
>>
>>
>> Any pointers?
>>
>>
>> On Sat, Jan 11, 2014 at 8:11 AM, Anthony  wrote:
>>
>>> Another one of our great undocumented gems. :-)
>>>
>>> --
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.com/book (Documentation)
>>> - http://github.com/web2py/web2py (Source code)
>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>> ---
>>> You received this message because you are subscribed to the Google 
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to web2py+un...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
>>
>> -- 
>>
>> ...
>> Teddy Lubasi Nyambe
>> Opensource Zambia
>> Lusaka, ZAMBIA
>>
>> Cell: +260 97 7760473
>> website: http://www.opensource.org.zm
>>
>> ~/
>> Human Knowledge belongs to the world! - AntiTrust
>>
>> Man is a tool-using animal. Without tools he is nothing, with tools he is 
>> all - Thomas Carlyle 1795-1881
>>
>> /~ 
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-11 Thread Anthony
It depends on how the particular exception class is implemented. In 
general, if you do str(error), you get the error message. I think in most 
exception classes, error.args[0] is also typically the error message. This 
is a general Python issue and not specific to web2py.

try:

except db._adapter.driver.IntegrityError as e:
return str(e)

Anthony

On Saturday, January 11, 2014 1:55:30 AM UTC-5, software.ted wrote:
>
> Hi Anthony!
>
> Those gems we need to know!!!, since i have to extract undocumented 
> details on this list, I would like to find out how i can then get system 
> generated messages cause there are many integrity error 
> descriptions...instead of me having one message like this:
>
> try:
> ...
> except db._adapter.driver.IntegrityError:
> err_msg = "Duplicate record in database"
>
> I would like to have a situation were i can get system messages of the 
> specific integrity error enountered:
>
> try:
> ...
> except db._adapter.driver.IntegrityError:
> err_msg = db.[some object].errorMessage
>
>
> Any pointers?
>
>
> On Sat, Jan 11, 2014 at 8:11 AM, Anthony  >wrote:
>
>> Another one of our great undocumented gems. :-)
>>
>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> -- 
>
> ...
> Teddy Lubasi Nyambe
> Opensource Zambia
> Lusaka, ZAMBIA
>
> Cell: +260 97 7760473
> website: http://www.opensource.org.zm
>
> ~/
> Human Knowledge belongs to the world! - AntiTrust
>
> Man is a tool-using animal. Without tools he is nothing, with tools he is 
> all - Thomas Carlyle 1795-1881
>
> /~ 
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-10 Thread Teddy Nyambe
Hi Anthony!

Those gems we need to know!!!, since i have to extract undocumented details
on this list, I would like to find out how i can then get system generated
messages cause there are many integrity error descriptions...instead of me
having one message like this:

try:
...
except db._adapter.driver.IntegrityError:
err_msg = "Duplicate record in database"

I would like to have a situation were i can get system messages of the
specific integrity error enountered:

try:
...
except db._adapter.driver.IntegrityError:
err_msg = db.[some object].errorMessage


Any pointers?


On Sat, Jan 11, 2014 at 8:11 AM, Anthony  wrote:

> Another one of our great undocumented gems. :-)
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
...
Teddy Lubasi Nyambe
Opensource Zambia
Lusaka, ZAMBIA

Cell: +260 97 7760473
website: http://www.opensource.org.zm

~/
Human Knowledge belongs to the world! - AntiTrust

Man is a tool-using animal. Without tools he is nothing, with tools he is
all - Thomas Carlyle 1795-1881

/~

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-10 Thread Anthony
Another one of our great undocumented gems. :-)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-10 Thread Teddy Nyambe
thanks. it worked. but where is this documented?


On Fri, Jan 10, 2014 at 4:09 PM, Anthony  wrote:

> IntegrityError is defined by the database driver, so needs to be imported.
> Actually, I forgot, we made this easier, so it is not adapter-dependent --
> you can do:
>
> try:
> ...
> except db._adapter.driver.IntegrityError:
> ...
>
> Another option is:
>
> def insert_error_handler(table, fields, error):
> [handle the error]
>
> db.mytable._on_insert_error = insert_error_handler
>
> There is also an _on_update_error callback.
>
> Anthony
>
> On Friday, January 10, 2014 3:53:17 AM UTC-5, software.ted wrote:
>
>> Tried the example you gave me:
>>
>> Try:
>> 
>> Except IntegrityError:
>> 
>>
>>
>> I am getting unresolved reference 'IntegrityError'
>>
>> Kind regards,
>>
>>
>> On Thu, Jan 9, 2014 at 6:01 PM, Teddy Nyambe  wrote:
>>
>>> Thanx Anthony,
>>>
>>> I will use [try]
>>> On 9 Jan 2014 15:52, "Anthony"  wrote:
>>>
 try:
 db.test.insert(...)
 except IntegrityError:
 [return friendly error message]

 Of course, if the inserts are done via form submission, you should
 instead add an IS_NOT_IN_DB validator, in which case, it will automatically
 check for duplicates and return the appropriate error message. Even if not
 using a form, you can make use of the validator by using the
 .validate_and_insert() method.

 Anthony

 On Thursday, January 9, 2014 2:31:00 AM UTC-5, software.ted wrote:
>
> Hi,
>
> I am trying to find out the best way to catch errors generated by
> web2py especially those genereted by say DAL. Say forinstance if I
> have a table:
>
> db.define_table('test', Field('xyz', 'integer', unique=True)
>
> If i insert a dublicate field will get the exception and ticket:
>
> IntegrityError: (1062, u"Duplicate entry 'X' for key 'xyz'")
>
> Now i want to catch such an error and send a better message to a user,
> not the ticket etc.
>
> Any ideas?
>
> --
> ...
>
> Teddy Lubasi Nyambe
> Opensource Zambia
> Lusaka, ZAMBIA
>
> Cell: +260 97 7760473
> website: http://www.opensource.org.zm
>
> ~/
> Human Knowledge belongs to the world! - AntiTrust
>
> Man is a tool-using animal. Without tools he is nothing, with tools he
> is all - Thomas Carlyle 1795-1881
>
> /~
>
  --
 Resources:
 - http://web2py.com
 - http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py (Source code)
 - https://code.google.com/p/web2py/issues/list (Report Issues)
 ---
 You received this message because you are subscribed to the Google
 Groups "web2py-users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to web2py+un...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.

>>>
>>
>>
>> --
>> 
>> ...
>> Teddy Lubasi Nyambe
>> Opensource Zambia
>> Lusaka, ZAMBIA
>>
>> Cell: +260 97 7760473
>> website: http://www.opensource.org.zm
>>
>> ~/
>> Human Knowledge belongs to the world! - AntiTrust
>>
>> Man is a tool-using animal. Without tools he is nothing, with tools he is
>> all - Thomas Carlyle 1795-1881
>>
>> /~
>>
>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
...
Teddy Lubasi Nyambe
Opensource Zambia
Lusaka, ZAMBIA

Cell: +260 97 7760473
website: http://www.opensource.org.zm

~/
Human Knowledge belongs to the world! - AntiTrust

Man is a tool-using animal. Without tools he is nothing, with tools he is
all - Thomas Carlyle 1795-1881

/~

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-10 Thread Anthony
IntegrityError is defined by the database driver, so needs to be imported. 
Actually, I forgot, we made this easier, so it is not adapter-dependent -- 
you can do:

try:
...
except db._adapter.driver.IntegrityError:
...

Another option is:

def insert_error_handler(table, fields, error):
[handle the error]

db.mytable._on_insert_error = insert_error_handler

There is also an _on_update_error callback.

Anthony

On Friday, January 10, 2014 3:53:17 AM UTC-5, software.ted wrote:
>
> Tried the example you gave me:
>
> Try: 
> 
> Except IntegrityError: 
> 
>
>
> I am getting unresolved reference 'IntegrityError'
>
> Kind regards,
>
>
> On Thu, Jan 9, 2014 at 6:01 PM, Teddy Nyambe 
> > wrote:
>
>> Thanx Anthony,
>>
>> I will use [try]
>> On 9 Jan 2014 15:52, "Anthony" > wrote:
>>
>>> try:
>>> db.test.insert(...)
>>> except IntegrityError:
>>> [return friendly error message]
>>>
>>> Of course, if the inserts are done via form submission, you should 
>>> instead add an IS_NOT_IN_DB validator, in which case, it will automatically 
>>> check for duplicates and return the appropriate error message. Even if not 
>>> using a form, you can make use of the validator by using the 
>>> .validate_and_insert() method.
>>>
>>> Anthony
>>>
>>> On Thursday, January 9, 2014 2:31:00 AM UTC-5, software.ted wrote:

 Hi, 

 I am trying to find out the best way to catch errors generated by 
 web2py especially those genereted by say DAL. Say forinstance if I 
 have a table: 

 db.define_table('test', Field('xyz', 'integer', unique=True) 

 If i insert a dublicate field will get the exception and ticket: 

 IntegrityError: (1062, u"Duplicate entry 'X' for key 'xyz'") 

 Now i want to catch such an error and send a better message to a user, 
 not the ticket etc. 

 Any ideas? 

 -- 
 ...
  

 Teddy Lubasi Nyambe 
 Opensource Zambia 
 Lusaka, ZAMBIA 

 Cell: +260 97 7760473 
 website: http://www.opensource.org.zm 

 ~/ 
 Human Knowledge belongs to the world! - AntiTrust 

 Man is a tool-using animal. Without tools he is nothing, with tools he 
 is all - Thomas Carlyle 1795-1881 

 /~ 

>>>  -- 
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.com/book (Documentation)
>>> - http://github.com/web2py/web2py (Source code)
>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to web2py+un...@googlegroups.com .
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>
>
> -- 
>
> ...
> Teddy Lubasi Nyambe
> Opensource Zambia
> Lusaka, ZAMBIA
>
> Cell: +260 97 7760473
> website: http://www.opensource.org.zm
>
> ~/
> Human Knowledge belongs to the world! - AntiTrust
>
> Man is a tool-using animal. Without tools he is nothing, with tools he is 
> all - Thomas Carlyle 1795-1881
>
> /~ 
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-10 Thread Teddy Nyambe
Tried the example you gave me:

Try:

Except IntegrityError:



I am getting unresolved reference 'IntegrityError'

Kind regards,


On Thu, Jan 9, 2014 at 6:01 PM, Teddy Nyambe  wrote:

> Thanx Anthony,
>
> I will use [try]
> On 9 Jan 2014 15:52, "Anthony"  wrote:
>
>> try:
>> db.test.insert(...)
>> except IntegrityError:
>> [return friendly error message]
>>
>> Of course, if the inserts are done via form submission, you should
>> instead add an IS_NOT_IN_DB validator, in which case, it will automatically
>> check for duplicates and return the appropriate error message. Even if not
>> using a form, you can make use of the validator by using the
>> .validate_and_insert() method.
>>
>> Anthony
>>
>> On Thursday, January 9, 2014 2:31:00 AM UTC-5, software.ted wrote:
>>>
>>> Hi,
>>>
>>> I am trying to find out the best way to catch errors generated by
>>> web2py especially those genereted by say DAL. Say forinstance if I
>>> have a table:
>>>
>>> db.define_table('test', Field('xyz', 'integer', unique=True)
>>>
>>> If i insert a dublicate field will get the exception and ticket:
>>>
>>> IntegrityError: (1062, u"Duplicate entry 'X' for key 'xyz'")
>>>
>>> Now i want to catch such an error and send a better message to a user,
>>> not the ticket etc.
>>>
>>> Any ideas?
>>>
>>> --
>>> ...
>>>
>>> Teddy Lubasi Nyambe
>>> Opensource Zambia
>>> Lusaka, ZAMBIA
>>>
>>> Cell: +260 97 7760473
>>> website: http://www.opensource.org.zm
>>>
>>> ~/
>>> Human Knowledge belongs to the world! - AntiTrust
>>>
>>> Man is a tool-using animal. Without tools he is nothing, with tools he
>>> is all - Thomas Carlyle 1795-1881
>>>
>>> /~
>>>
>>  --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>


-- 
...
Teddy Lubasi Nyambe
Opensource Zambia
Lusaka, ZAMBIA

Cell: +260 97 7760473
website: http://www.opensource.org.zm

~/
Human Knowledge belongs to the world! - AntiTrust

Man is a tool-using animal. Without tools he is nothing, with tools he is
all - Thomas Carlyle 1795-1881

/~

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: REF: DAL Catching errors

2014-01-09 Thread Teddy Nyambe
Thanx Anthony,

I will use [try]
On 9 Jan 2014 15:52, "Anthony"  wrote:

> try:
> db.test.insert(...)
> except IntegrityError:
> [return friendly error message]
>
> Of course, if the inserts are done via form submission, you should instead
> add an IS_NOT_IN_DB validator, in which case, it will automatically check
> for duplicates and return the appropriate error message. Even if not using
> a form, you can make use of the validator by using the
> .validate_and_insert() method.
>
> Anthony
>
> On Thursday, January 9, 2014 2:31:00 AM UTC-5, software.ted wrote:
>>
>> Hi,
>>
>> I am trying to find out the best way to catch errors generated by
>> web2py especially those genereted by say DAL. Say forinstance if I
>> have a table:
>>
>> db.define_table('test', Field('xyz', 'integer', unique=True)
>>
>> If i insert a dublicate field will get the exception and ticket:
>>
>> IntegrityError: (1062, u"Duplicate entry 'X' for key 'xyz'")
>>
>> Now i want to catch such an error and send a better message to a user,
>> not the ticket etc.
>>
>> Any ideas?
>>
>> --
>> ...
>>
>> Teddy Lubasi Nyambe
>> Opensource Zambia
>> Lusaka, ZAMBIA
>>
>> Cell: +260 97 7760473
>> website: http://www.opensource.org.zm
>>
>> ~/
>> Human Knowledge belongs to the world! - AntiTrust
>>
>> Man is a tool-using animal. Without tools he is nothing, with tools he
>> is all - Thomas Carlyle 1795-1881
>>
>> /~
>>
>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.