• Timeout error with www

    From saito@saitology9@gmail.com to comp.lang.tcl on Sun Jul 20 14:04:47 2025
    From Newsgroup: comp.lang.tcl

    I am using www to fetch a url. I want to catch timeouts in a try-trap
    block. I believe I am following the exact same syntax in the tests for
    the package but it still throws an error.


    package req www
    set url ...

    % try {www get $url} trap {WWW DATA TIMEOUT} {msg info} {puts timeout}
    couldn't open socket: connection timed out


    % try {www get $url} trap {WWW TIMEOUT} {msg info} {puts timeout}
    couldn't open socket: connection timed out


    Any suggestion to make this work? Is there a list of codes to trap?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Schelte@nospam@wanadoo.nl to comp.lang.tcl on Tue Jul 22 21:12:35 2025
    From Newsgroup: comp.lang.tcl

    On 20/07/2025 20:04, saito wrote:
    I am using www to fetch a url. I want to catch timeouts in a try-trap
    block. I believe I am following the exact same syntax in the tests for
    the package but it still throws an error.


    package req www
    set url ...

    % try {www get $url} trap {WWW DATA TIMEOUT} {msg info} {puts timeout} couldn't open socket: connection timed out


    % try {www get $url} trap {WWW TIMEOUT} {msg info} {puts timeout}
    couldn't open socket: connection timed out


    Any suggestion to make this work? Is there a list of codes to trap?

    You can add an "on error" handler to find out the error code for
    different cases:

    package require www

    set url http://10.10.10.10/

    try {
    www get $url
    } trap {WWW DATA TIMEOUT} {msg info} {
    puts timeout
    } on error {msg info} {
    puts "Unexpected error: [dict get $info -errorcode]"
    }

    Running that will show that the error code for this specific failure is:
    WWW CONNECT {couldn't open socket: connection timed out}


    Schelte

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Wed Jul 23 12:24:38 2025
    From Newsgroup: comp.lang.tcl

    On 7/22/2025 3:12 PM, Schelte wrote:
    On 20/07/2025 20:04, saito wrote:
    Any suggestion to make this work? Is there a list of codes to trap?

    You can add an "on error" handler to find out the error code for
    different cases:

    package require www

    set url http://10.10.10.10/

    try {
        www get $url
    } trap {WWW DATA TIMEOUT} {msg info} {
        puts timeout
    } on error {msg info} {
        puts "Unexpected error: [dict get $info -errorcode]"
    }

    Running that will show that the error code for this specific failure is:
    WWW CONNECT {couldn't open socket: connection timed out}


    Thanks! The on-error works nicely.

    I eventually did discover the WWW CONNECT label after printing
    everything out but I wasn't sure if it was internal to the package or not.




    --- Synchronet 3.21a-Linux NewsLink 1.2