This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

TCL HTTP: can't read "state(after)"

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

TCL HTTP: can't read "state(after)"

Post by De Kus »

I wonder if I do something wrong. Full error:

Code: Select all

[-RO^Bot-] [12:58:59] #De_Kus# set errorInfo
[-RO^Bot-] Currently: can't read "state(after)": no such element in array
[-RO^Bot-] Currently:     while executing
[-RO^Bot-] Currently: "after cancel $state(after)"
This occurs with most (all?) asyncron HTTP requests I use in eggdrop. The general problem is obvious: after using ::http::cleanup $token, $state(after) has already been removed before its called by HTTP. But what else should I do? Do you believe using utimer 1 with that command would be a solution or rather a workaround? Is that an error of the HTTP package and should be reported to tcl.tk?

If greped this part of the script:

Code: Select all

[-RO^Bot-] [14:02:58] tcl: evaluate (.tcl): exec grep after /usr/local/lib/tcl8.4/http2.5/http.tcl
[-RO^Bot-] Tcl:     catch {after cancel $state(after)}
no nice way imho, they could first check if exists state(after) to prevent occurance of unneccessary TCL errors.
This occurs at least till HTTP 2.5.2 from TCL 8.4.12.

Edit: not even after 60000 for http::cleanup or a set state(after) "" after the cleanup helps...
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

I gather nothing further has been done to fix this (not that I'm surprised)?

De Kus: Did you lodge a bug report?
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I've only seen that error when calling ::http::cleanup directly after an error test, like in:

Code: Select all

catch {set page [::http::geturl $movieurl -timeout $::movietimeout]} error
	if {[string match -nocase "*couldn't open socket*" $error]} {
		puthelp "PRIVMSG $chan :Error: couldn't connect to filmspot.com..Try again later."
      ::http::cleanup $page
		return
	}
	if { [::http::status $page] == "timeout" } {
		puthelp "PRIVMSG $chan :Error: Connection to filmspot.com timed out..Try again later."
      ::http::cleanup $page
		return
	}
	set html [::http::data $page]
That's how I used to do my web procs. Now I just leave off the http::cleanup call.

I posted about the same error messages before, and was informed that http::cleanup is on a timer anyway, so calling it directly was unneeded. Haven't seen that error in the scripts I fixed that don't call http::cleanup (except at the end, after getting data.)

IOW, my newer scripts take the form:

Code: Select all

catch {set page [::http::geturl $movieurl -timeout $::movietimeout]} error
	if {[string match -nocase "*couldn't open socket*" $error]} {
		puthelp "PRIVMSG $chan :Error: couldn't connect to filmspot.com..Try again later."
		return
	}
	if { [::http::status $page] == "timeout" } {
		puthelp "PRIVMSG $chan :Error: Connection to filmspot.com timed out..Try again later."
		return
	}
	set html [::http::data $page]
	::http::cleanup $page
Z
Zircon
Op
Posts: 191
Joined: Mon Aug 21, 2006 4:22 am
Location: Montreal

Post by Zircon »

Code: Select all

<Anti-Flood> [03:06] #Owner# set errorInfo
<Anti-Flood> Currently: can't read "state(after)": no such element in array
<Anti-Flood> Currently:     while executing
<Anti-Flood> Currently: "after cancel $state(after)"
i always was trying to identify the script causing this error. So finally i understand it s related to the HTTP. Indeed, i use many scripts that deals with HTTP.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

De Kus wrote:no nice way imho, they could first check if exists state(after) to prevent occurance of unneccessary TCL errors.
Testing this theory it seems to work...

lines 165,166 change to:

Code: Select all

    if {[info exists state(sock)]} { catch {close $state(sock)} }
    if {[info exists state(after)]} { catch {after cancel $state(after)} }
lines 197,198 change to:

Code: Select all

    if {[info exists state(sock)]} { catch {fileevent $state(sock) readable {}} }
    if {[info exists state(sock)]} { catch {fileevent $state(sock) writable {}} }
Using HTTP 2.4.2 and changing the lines above it seems to solve the problem. Running various http queries and a quick .set errrorInfo afterwards yields the following...
<speechles> !g google
<sp33chy> 1,460,000,000 Results | Google @ http://www.google.com/ | Google Maps @ http://maps.google.com/ | Google Video @ http://video.google.com/ | Google Groups @ http://groups.google.com/
*meanwhile on the partyline directly after*
<speechles> .set errorInfo
<sp33chy> Currently: couldn't create error file for command: no such file or directory
<sp33chy> Currently: while executing
<sp33chy> Currently: "exec chmod 700 $nb_dir"

<speechles> !w .jasd asd
<sp33chy> Socket Error accessing 'jasd.wikipedia.org' .. Does it exist?
*meanwhile on the partyline directly after*
<speechles> .set errorInfo
<sp33chy> Currently: couldn't open socket: host is unreachable
<sp33chy> Currently: while executing
<sp33chy> Currently: "::http::geturl $query -timeout [expr 1000 * 5]"
Notice the top error message which is usually a state(after) error is instead an error message reporting no error found to report, so this does work as a fix. If someone can shed some light if this is indeed an http package bug it would be wonderful. ;)
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

I use only one script that grabs data from the web (and causes this annoyance), the OV2 version of B0unTy's iMDB.tcl.

It uses:

Code: Select all

::http::Finish $page
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Post Reply