Ask a Question related to Ruby, Design and Development.

  1. #1

    Default retry does not work

    matz:

    you rejected my rcr on garden saying that retry already does it. but it does not. maybe there's a trick to it? but i could not read your example b/c it was cut off by the < --you have to use &lt; [Aside: why hasn't this been fixed at garden? argghhh..]

    so please show me how resume would work with retry here. here is the example again:

    def resume_example(x)
    begin
    print x
    x = x + 4
    if x < 10
    raise
    end
    print x
    rescue
    x = 10
    resume # if retry -> 51014
    end
    puts
    end
    resume_example(5) # -> 510

    thanks matz,
    -t0


    T. Onoma Guest

  2. Similar Questions and Discussions

    1. PDF request service (second retry)
      greetings and salutations, o smarter than i. i've been working on a solution to secure the delivery of pdfs to client browsers. we're introducing...
    2. PDF request service (retry post)
      ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
    3. CFMX7 PROBLEM!!! Auto retry upon request timeout
      Just upgraded to CFMX7 from CF5. Basically everything is running smoothly expect one serious problem. We have a process which takes more than 3...
    4. A code snippet: Controlled retry
      I sometimes find myself retrying operations when in a networked situation (e.g., maybe server isn't up, just try again). I just wrote this little...
    5. ssl bad write retry
      I've got a Ruby script that uploads a file to another Ruby cgi script. It works fine on a non-ssl site, but when I use the SSL site with net/https,...
  3. #2

    Default Re: retry does not work

    >>>>> "T" == T Onoma <transami@runbox.com> writes:

    T> you rejected my rcr on garden saying that retry already does it. but it
    T> does not. maybe there's a trick to it? but i could not read your example
    T> b/c it was cut off by the < --you have to use &lt; [Aside: why hasn't
    T> this been fixed at garden? argghhh..]

    Well the example was probably

    def resume_example(x)
    print x
    x += 4
    begin
    raise if x < 10
    print x
    rescue
    x = 10
    retry
    end
    puts
    end



    Guy Decoux




    ts Guest

  4. #3

    Default Re: retry does not work

    Guy Decoux:
    > Well the example was probably
    >
    > def resume_example(x)
    > print x
    > x += 4
    > begin
    > raise if x < 10
    > print x
    > rescue
    > x = 10
    > retry
    > end
    > puts
    > end
    you have refactored my code to achieve the result. is all code so easily refactored?

    def i_am_libaray_code
    # this is a library call
    # to be used in many differnt apps
    # do not add user interface code!
    raise SpecialWaring, "Warning, incoming!"
    ...
    end

    def resume_example(x)
    begin
    i_am_library_code
    rescue SpecialWaring => e
    puts e
    resume
    end
    end

    i can not refactor the lib call to conatin stdout, and i need a message from it about its status. perhaps there is another way to do this. if you know please tell!

    -t0

    T. Onoma Guest

  5. #4

    Default Re: retry does not work

    Hi,

    In message "retry does not work"
    on 03/11/20, "T. Onoma" <transami@runbox.com> writes:

    |you rejected my rcr on garden saying that retry already does it. but it does not. maybe there's a trick to it? but i could not read your example b/c it was cut off by the < --you have to use &lt; [Aside: why hasn't this been fixed at garden? argghhh..]
    |
    |so please show me how resume would work with retry here. here is the example again:

    Check the code carefully (note where "begin" is). It's not just
    replacing resume with retry. "retry" jumps back to "begin".

    |def resume_example(x)
    | begin
    | print x
    | x = x + 4
    | if x < 10
    | raise
    | end
    | print x
    | rescue
    | x = 10
    | resume # if retry -> 51014
    | end
    | puts
    |end
    |resume_example(5) # -> 510

    def resume_example(x)
    print x
    x = x + 4
    begin
    if x < 10
    raise
    end
    print x
    rescue
    x = 10
    retry
    end
    puts
    end
    resume_example(5) # -> 510

    matz.

    Yukihiro Matsumoto Guest

  6. #5

    Default Re: retry does not work

    >>>>> "T" == T Onoma <transami@runbox.com> writes:

    T> i can not refactor the lib call to conatin stdout, and i need a message
    T> from it about its status. perhaps there is another way to do this. if
    T> you know please tell!

    Becuase you can't refactor the library, you *can't* use resume like you
    want use it because you know nothing about the internal of this library



    Guy Decoux



    ts Guest

  7. #6

    Default Re: retry does not work


    "T. Onoma" <transami@runbox.com> schrieb im Newsbeitrag
    news:E1AMm57-0002fp-HX@odie.runbox.com...
    > Guy Decoux:
    >
    > > Well the example was probably
    > >
    > > def resume_example(x)
    > > print x
    > > x += 4
    > > begin
    > > raise if x < 10
    > > print x
    > > rescue
    > > x = 10
    > > retry
    > > end
    > > puts
    > > end
    >
    > you have refactored my code to achieve the result. is all code so easily
    refactored?
    >
    > def i_am_libaray_code
    > # this is a library call
    > # to be used in many differnt apps
    > # do not add user interface code!
    > raise SpecialWaring, "Warning, incoming!"
    > ...
    > end
    >
    > def resume_example(x)
    > begin
    > i_am_library_code
    > rescue SpecialWaring => e
    > puts e
    > resume
    > end
    > end
    >
    > i can not refactor the lib call to conatin stdout, and i need a message
    from it about its status. perhaps there is another way to do this. if you
    know please tell!

    What strikes me is that you use "resume" in the rescue clause instead of
    "retry". Is that on purpose or is maybe a simple misspelling the reason
    for your frustration.

    Kind regards

    robert

    Robert Klemme Guest

  8. #7

    Default Re: retry does not work

    Guy:
    > Becuase you can't refactor the library, you *can't* use resume like you
    > want use it because you know nothing about the internal of this library
    no, i wrote the library. ;) but i don't want interface code in it so i can resue it under differnt circumstances.

    -t0


    T. Onoma Guest

  9. #8

    Default Re: retry does not work

    >>>>> "T" == T Onoma <transami@runbox.com> writes:

    T> no, i wrote the library. ;) but i don't want interface code in it so i
    T> can resue it under differnt circumstances.

    Then change it : your need of resume in this case, just means that your
    library was badly designed


    Guy Decoux



    ts Guest

  10. #9

    Default Re: retry does not work

    Hi,

    In message "Re: retry does not work"
    on 03/11/20, "T. Onoma" <transami@runbox.com> writes:

    |you have refactored my code to achieve the result. is all code so easily refactored?

    Not all, but most.

    Your "resume" makes exception handling much harder. With "resume",
    every raise can be re-entered, that means programmers need to care
    about re-entrance always.

    So allowing new thing is not always a good thing.

    matz.

    Yukihiro Matsumoto Guest

  11. #10

    Default Re: retry does not work

    Hi matz,

    thanks for reposting, someone should really fix that bug on ruby garden.

    so Guy gave me same answer. i have problem with it. could you look at those and let me know? ( you probably already are \:)

    -t0

    T. Onoma Guest

  12. #11

    Default Re: retry does not work

    Guy:
    > T> no, i wrote the library. ;) but i don't want interface code in it so i
    > T> can resue it under differnt circumstances.
    >
    > Then change it : your need of resume in this case, just means that your
    > library was badly designed
    thats crap.

    were taking about seperation of concerns --that's not bad design. i have a library i use for downloading files. i have a user interface script that uses the library. things happen in the library and if the user has set verbose more i should be able to report them to the user *without* having to write special esoteric message passing code.

    sounds aweful dosen't it? come on, are you goating me?

    -ts


    T. Onoma Guest

  13. #12

    Default Re: retry does not work

    >>>>> "T" == T Onoma <transami@runbox.com> writes:

    T> were taking about seperation of concerns --that's not bad design. i have
    T> a library i use for downloading files. i have a user interface script
    T> that uses the library. things happen in the library and if the user has
    T> set verbose more i should be able to report them to the user *without*
    T> having to write special esoteric message passing code.

    You are raising an exception, this is, for me, different than sending
    message to stdout

    Guy Decoux

    ts Guest

  14. #13

    Default Re: retry does not work

    matz:
    > Your "resume" makes exception handling much harder. With "resume",
    > every raise can be re-entered, that means programmers need to care
    > about re-entrance always.
    >
    > So allowing new thing is not always a good thing.
    worry? isn't that what testers are for ;)

    okay, so maybe there could be an option put on raise to allow resuming?

    just as an example of what this could do: tanaka is adding hook into open_uri to do progress reporting of download. to make it work you have to pass a lambda that acts on progress. but with resume you could raise a ProgressException(pos) and resume, which is much cleaner.

    -t0

    T. Onoma Guest

  15. #14

    Default Re: retry does not work

    > You are raising an exception, this is, for me, different than sending
    > message to stdout
    okay, i grant you that was not the intention of raise when designed. but a rose by any other name....

    so what other means are there? should a raise_message be added? or maybe you are right. maybe my library is "badly designed", but if so then tell me what would the alternative be that achieves such seperation?

    -t0

    T. Onoma Guest

  16. #15

    Default Re: retry does not work

    Hi,

    In message "Re: retry does not work"
    on 03/11/20, "T. Onoma" <transami@runbox.com> writes:

    | so Guy gave me same answer. i have problem with it. could you look at those and let me know? ( you probably already are \:)

    I'm sorry; which is your problem? [ruby-talk:85791]?

    In message [ruby-talk:85791], you wrote:

    |were taking about seperation of concerns --that's not bad design. i
    |have a library i use for downloading files. i have a user interface
    |script that uses the library. things happen in the library and if the
    |user has set verbose more i should be able to report them to the user
    |*without* having to write special esoteric message passing code.

    "resume" won't work well unless both your code and the user code know
    each other (the user code must care that raise might resume; your code
    must know how to fix up the exception cause). In that case, I think
    you can make "retry" work, otherwise you can't make them work well
    anyway.

    matz.


    Yukihiro Matsumoto Guest

  17. #16

    Default Re: retry does not work

    Hi,

    In message "Re: retry does not work"
    on 03/11/20, "T. Onoma" <transami@runbox.com> writes:

    |just as an example of what this could do: tanaka is adding hook into open_uri to do progress reporting of download. to make it work you have to pass a lambda that acts on progress. but with resume you could raise a ProgressException(pos) and resume, which is much cleaner.

    Sounds like exception abuse for me. You can use continuation if you
    want to do something like that.

    matz.


    Yukihiro Matsumoto Guest

  18. #17

    Default Re: retry does not work

    >>>>> "T" == T Onoma <transami@runbox.com> writes:

    T> so what other means are there? should a raise_message be added? or maybe
    T> you are right. maybe my library is "badly designed", but if so then tell
    T> me what would the alternative be that achieves such seperation?

    svg% cat b.rb
    #!./ruby

    def send_message
    warn "message"
    end

    $-w = nil

    puts "before"
    send_message
    puts "after"

    class A
    def write(string)
    puts "a nice message #{string}"
    end
    end

    $stderr = A.new
    $-w = true

    send_message
    svg%


    svg% ruby b.rb
    before
    after
    a nice message message
    a nice message
    svg%



    Guy Decoux


    ts Guest

  19. #18

    Default Re: retry does not work

    > "resume" won't work well unless both your code and the user code know
    > each other (the user code must care that raise might resume; your code
    > must know how to fix up the exception cause). In that case, I think
    > you can make "retry" work, otherwise you can't make them work well
    > anyway.
    that is a good point, but the alternative seems to be passing proc or passing self. self seems like over kill, but passing proc is messy. no win situation here? perhaps this suggests another facility like raise but that does not halt execution. rather it moves up the call chain looking for a handler, if it finds one it executes, if not forget it, and then resumes execution. better RCR?

    thanks,
    -t0

    T. Onoma Guest

  20. #19

    Default Re: retry does not work

    Hi,

    In message "Re: retry does not work"
    on 03/11/20, "T. Onoma" <transami@runbox.com> writes:

    |that is a good point, but the alternative seems to be passing proc or passing self. self seems like over kill, but passing proc is messy. no win situation here? perhaps this suggests another facility like raise but that does not halt execution. rather it moves up the call chain looking for a handler, if it finds one it executes, if not forget it, and then resumes execution. better RCR?

    It's called "coroutine". If you are going to write new RCR, I
    recommend you to google it first.

    matz.


    Yukihiro Matsumoto Guest

  21. #20

    Default Re: retry does not work


    "Yukihiro Matsumoto" <matz@ruby-lang.org> schrieb im Newsbeitrag
    news:1069327343.081885.18914.nullmailer@picachu.ne tlab.jp...
    > Hi,
    >
    > In message "Re: retry does not work"
    > on 03/11/20, "T. Onoma" <transami@runbox.com> writes:
    >
    > |just as an example of what this could do: tanaka is adding hook into
    open_uri to do progress reporting of download. to make it work you have to
    pass a lambda that acts on progress. but with resume you could raise a
    ProgressException(pos) and resume, which is much cleaner.
    >
    > Sounds like exception abuse for me.
    Definitely! That's not an exceptional condition, but rather a case for
    regular invocation of a callback.
    > You can use continuation if you
    > want to do something like that.
    Isn't that a bit overkill? Hm...

    robert

    Robert Klemme Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139