Problem with "Exception" - suddenly stopped working

Hello,

I’m having a hard time with an exception handling. It’s part of a simple
ruby script which fetches user’s tweets and dumps into an SQLite3
database.

The code and the error can be found here:
http://codepad.org/WQN2cYfi#comment-5lrGPpKo

The strange thing is that it was working fine and suddenly stopped. I
can’t recall making an changes related to this code snippet which could
affect it’s behavior.

Any help/thoughts would be welcome,

best regards

Panagiotis A.

IMHO ~PERHAPS~ the begin rescue is not working because the exception
is not being propagated or the process is being abruptly terminated
(without raising exceptions). (Note: no experience with this gem)

Let’s see if somebody else more experienced knows the answer.

Meantime, look at this code as an example.

http://codepad.org/f4g9BIEa

Abinoam Jr.

On Thu, Jan 12, 2012 at 2:01 PM, Panagiotis A.

On Thu, Jan 12, 2012 at 10:04 PM, Abinoam Jr. [email protected] wrote:

Abinoam Jr.

Hi Abinoam, it is easier to follow the thread if you would write your
reply
on the
bottom (ref. “no top quoting”).

I continue below.

The strange thing is that it was working fine and suddenly stopped. I
can’t recall making an changes related to this code snippet which could
affect it’s behavior.

Any help/thoughts would be welcome,

It looks like the actual “exception” (I quote it because I am not sure
what it is),
is called:

Twitter::Error::BadGateway

Very speculative … could you ask it’s ancestor tree?

Twitter::Error::BadGateway.class

Like this:

[email protected]:~$ irb
001:0> Exception.ancestors
=> [Exception, Object, Kernel, BasicObject]
002:0> RuntimeError
=> RuntimeError
003:0> RuntimeError.ancestors
=> [RuntimeError, StandardError, Exception, Object, Kernel, BasicObject]
004:0> RuntimeError.new.kind_of?(Exception)
=> true
005:0> RUBY_VERSION
=> “1.9.3”

Maybe (??) it does not inherit from Exception (the actual class) ??

Very speculative …

I believe an exception will only be trapped by the rescue Something
if the “exception.is_a?(Something)”

HTH (but not sure),

Peter

Hello,

thanks all for the answers.

On 12 Ιαν 2012, at 22:35 , Peter V. wrote:

Twitter::Error::BadGateway.ancestors

that is …

Peter

Here is the ancestors output:

greyjewel:Morula atma$ cat test.rb && ruby1.9 test.rb
require “twitter”
puts Twitter::Error::BadGateway.ancestors
[…]
Twitter::Error::BadGateway
Twitter::Error::ServerError
Twitter::Error
StandardError
Exception
Object
Kernel
BasicObject
greyjewel:Morula atma$

So my error is “BadGateway” but should I use this like:

[…]
rescue Exception => (Twitter::Error::BadGateway)
[…]

I’m not sure where to go from here.

On Thu, Jan 12, 2012 at 10:33 PM, Peter V.
<[email protected]

wrote:

Very speculative … could you ask it’s ancestor tree?

Twitter::Error::BadGateway.class

Correction

Twitter::Error::BadGateway.ancestors

that is …

Peter

On Thu, Jan 12, 2012 at 8:45 PM, Panagiotis A.
[email protected] wrote:

StandardError
[…]

I’m not sure where to go from here.

(Bottom commenting. Thanks Peter).

If you put Twitter::Error::BadGateway it’ll treat only this particular
error.

And there’s much more.

Look at the ones raised by the twitter gem itself.

https://github.com/jnunemaker/twitter/tree/master/lib/twitter/error

Abinoam Jr.

On Fri, Jan 13, 2012 at 12:23 PM, Abinoam Jr. [email protected] wrote:

wrote:
that is …
Twitter::Error::BadGateway

[…]
rescue Exception => (Twitter::Error::BadGateway)

I think that should be (untested)

rescue Twitter::Error => e

and then you can do usefull things with ‘e’, preferably based on it’s
class.

e.to_s
e.class

Look at the ones raised by the twitter gem itself.

https://github.com/jnunemaker/twitter/tree/master/lib/twitter/error

Indeed. Thanks for that pointer.

So it seems

rescue Twitter::Error should catch all exceptions from the Twitter
gem.

Curious if the OP was able to solve the problem now with mentioning an
explicit Exception class?

HTH,

Peter

Hello,

On 13 Ιαν 2012, at 13:22 , Peter V. wrote:

On Thu, Jan 12, 2012 at 10:33 PM, Peter V. <
Twitter::Error::BadGateway.ancestors
puts Twitter::Error::BadGateway.ancestors

and then you can do usefull things with ‘e’, preferably based on it’s class.

e.to_s
e.class

Thanks for the hint. Doesn’t work though. The script comes out with the
same error.

And there’s much more.
rescue Twitter::Error should catch all exceptions from the Twitter gem.

Curious if the OP was able to solve the problem now with mentioning an
explicit Exception class?

HTH,

Peter

Thanks for the explanations. As a result I got a deeper understanding of
exceptions than before. However, I think the problem lies elsewhere.

The prior code had just a ‘rescue’ clause. As Peter said, it should work
with “Exception => e” also, although I don’t have any interest in
printing the error here. I’m using ‘retry’ for 3 times, then the program
exists with a message.

I have the feeling that for some reason the script breaks before
reaching the rescue keyword.

Thanks for the help. I’ll probably re-write the function from scratch,
see if I get the same errors.

Here is the entire script: http://codepad.org/5T32AAXW

best regards


Peter V.
http://twitter.com/peter_v
http://rails.vandenabeele.com

Panagiotis A.

Unfortunately (or fortunately) your script is working pretty well in my
setup.

Using /home/abinoam/.rvm/gems/ruby-1.9.2-p290

The installed gem is twitter 2.0.2.

And I couldn’t reproduce your bug.

But, note that you are redefining the update method. Line 36 and line
110.
The last one (the one that is really executed) lacks any begin, rescue
clause.

Abinoam Jr.

On Fri, Jan 13, 2012 at 10:26 AM, Panagiotis A.

Hello,

On 13 Ιαν 2012, at 18:29 , Abinoam Jr. wrote:

Unfortunately (or fortunately) your script is working pretty well in my setup.

Using /home/abinoam/.rvm/gems/ruby-1.9.2-p290

The installed gem is twitter 2.0.2.

And I couldn’t reproduce your bug.

But, note that you are redefining the update method. Line 36 and line 110.
The last one (the one that is really executed) lacks any begin, rescue clause.

Thanks for noting. This was pretty stupid of me. I have a second version
of this program which implements support for other protocols. Since
however I needed to calculate some stats just from twitter, I created
this script which will work just for twitter. I write code using
TextMate usually but recently I switched to VIM and I copied two times
the update method without noting, probably removing the begin/rescue
clause… Since I use small terminal window and moving with ‘/keywords’
in terminal I didn’t noticed :frowning:

Thanks for pointing out, I feel a bit embarrassed. I was even about to
compile ruby-1.9.2 to check it if it was working with that version.

Abinoam Jr.

Best Regards

Panagiotis A.

On Fri, Jan 13, 2012 at 1:37 PM, Panagiotis A.
[email protected] wrote:

The wise man said: “Never argue with an idiot, he brings you down to his level
and beat you with experience.”
So… did it work this time?

Don’t be embarassed at all. And, I’m glad I could help.

For example, look at PeterVandenabeele, he complained of my
“top-commeting” in this thread. So I began “bottom-commenting” in
respect to him (and the standards fron somewhere).

BUT, he himself, at this same thread, top commented.

:wink: :smiley:

(I just could’n let this pass unoticed. Please don’t be upset with
Peter.)

Cheers Peter!!! :slight_smile:

Abinoam Jr.

On Fri, Jan 13, 2012 at 2:26 PM, Panagiotis A.
[email protected]wrote:

I have the feeling that for some reason the script breaks before reaching
the rescue keyword.

Well, you could put ‘puts’ everywhere to check that …

Thanks for the help. I’ll probably re-write the function from scratch, see
if I get the same errors.

The only thing I can think of now is a bug that was reported some time
ago
where an
exception thrown in an ‘eval’ was not caught correctly … I googled for
it, but couldn’t
find it back immediately.

Also, what happens if you take it out of that “Benchmark” block? Just
guessing …

HTH,

Peter

On Fri, Jan 13, 2012 at 8:32 PM, Abinoam Jr. [email protected] wrote:

For example, look at Peter V., he complained of my
“top-commeting” in this thread. So I began “bottom-commenting” in
respect to him (and the standards fron somewhere).

BUT, he himself, at this same thread, top commented.

No worries.

(Firstly) Just for my understanding, could you show me the message
where you saw me top commenting in this thread. I checked the
5 messages I sent earlier in this thread and could not immediately
find the one where I “top quoted”.

:wink: :smiley:

(I just could’n let this pass unoticed. Please don’t be upset with Peter.)

(Secondly) No problem again … sometimes, I do “top quote”, when it is
like a global answer on an entire thread (e.g. “OK with everything”).

and …

‘Thirdly, the [pirate] code is more what you’d call “guidelines” than
actual rules.’

(as a sailor I learned this from Captain Barbossa in the Pirates of the
Caribbean
http://www.youtube.com/watch?v=b6kgS_AwuH0 (@ 0:12) )

Cheers Peter!!! :slight_smile:

You’re welcome :slight_smile:

Peter

Hello,

Yes everything works fine now. I’m just doing some fine tunning:
https://github.com/atmosx/morula

thanks guys

On 13 Ιαν 2012, at 20:32 , Abinoam Jr. wrote:

personal info: http://www.convalesco.org

BUT, he himself, at this same thread, top commented.

:wink: :smiley:

(I just could’n let this pass unoticed. Please don’t be upset with Peter.)

Cheers Peter!!! :slight_smile:

Abinoam Jr.

Panagiotis A.

On Fri, Jan 13, 2012 at 9:09 PM, Peter V.
[email protected] wrote:

No worries.

(Firstly) Just for my understanding, could you show me the message
where you saw me top commenting in this thread. I checked the
5 messages I sent earlier in this thread and could not immediately
find the one where I “top quoted”.

No, I just can’t show you the message.
Just because now you made me notice that I was mistaken!!! (._.)

Peter, you’re completly right.
What a shame of mine.
The new layout of GMail has fooled me a little.
It has hidden the text before you’re reply, so it seemed to me that
you had top commented (because the text before it was hidden).
By the way, I was just joking/kidding.
And I really thank you your advise.
I’m pretty “hard wired” on top-commenting and it’ll be hard to get
used to bottom-commenting.
But, as a proof, look at this message…
https://www.ruby-forum.com/topic/3426196#1040756
It was after your advise to bottom-comment. It was me trying to get
used to it.

Hello,

On 14 Ιαν 2012, at 04:15 , Abinoam Jr. wrote:

No, I just can’t show you the message.
used to bottom-commenting.
But, as a proof, look at this message…
https://www.ruby-forum.com/topic/3426196#1040756
It was after your advise to bottom-comment. It was me trying to get
used to it.

Just to add my two cents on this off-topic thread, in mailing lists like
“sikurezza” [1] you don’t get passed through the moderator using top
quoting. It’s standard netiquette.

On hindsight, no one will moderate your emails if you do it here hehe,
so don’t bother, it’s not a big deal imho.

and …

You’re welcome :slight_smile:

Peter


Peter V.
http://twitter.com/peter_v
http://rails.vandenabeele.com

[1] http://www.sikurezza.org/

Panagiotis A.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs