Sign in to follow this  
Followers 0
VeeDub

IE error handling

14 posts in this topic

Hi,

I have a couple questions in regard to error handling that I hope someone can help with some troubleshooting advice.

Here is the code for the error handler that I am using:

Func MyErrHandler()
   ; Important: the error object variable MUST be named $oIEErrorHandler
    $ErrorScriptline = $oIEErrorHandler.scriptline
    $ErrorNumber = $oIEErrorHandler.number
    $ErrorNumberHex = Hex($oIEErrorHandler.number, 8)
    $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2)
    $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2)
    $ErrorSource = $oIEErrorHandler.Source
    $ErrorHelpFile = $oIEErrorHandler.HelpFile
    $ErrorHelpContext = $oIEErrorHandler.HelpContext
    $ErrorLastDllError = $oIEErrorHandler.LastDllError
    $ErrorOutput = ""
    $ErrorOutput = @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & " "
    $ErrorOutput &= "--> Error " & @CR
    $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & " "
    $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & " "
    $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & " "
    $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & " "
    $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & " "
    $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & " " 
    $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError & " "

    $Activity_Log = FileOpen($Activity_File,1)
    FileWriteLine($Activity_Log,$ErrorOutput)
    FileClose($Activity_Log)

    SetError(1)
    Return
EndFunc

Here is an extract from the log

2006-08-31 21:34 _IECreate oIE2 www.freedomtaxation.com
2006-08-31 21:34 --> Error 
----> $ErrorScriptline = 1026 ----> $ErrorNumberHex = 80020006 ----> $ErrorNumber = -2147352570 ----> $ErrorWinDescription = Unknown name. ----> $ErrorDescription =  ----> $ErrorSource =  ----> $ErrorLastDllError = 0 
2006-08-31 21:34 _IECreate oIE2 www.leslienagyassociates.com
2006-08-31 21:35 --> Error 
----> $ErrorScriptline = 348 ----> $ErrorNumberHex = 800706BE ----> $ErrorNumber = -2147023170 ----> $ErrorWinDescription = The remote procedure call failed. ----> $ErrorDescription =  ----> $ErrorSource =  ----> $ErrorLastDllError = 0 
2006-08-31 21:35 --> Error 
----> $ErrorScriptline = 352 ----> $ErrorNumberHex = 800706BA ----> $ErrorNumber = -2147023174 ----> $ErrorWinDescription = The RPC server is unavailable. ----> $ErrorDescription =  ----> $ErrorSource =  ----> $ErrorLastDllError = 0

The error in scriptline 1026 seems to be due to something about the URL www.freedomtaxation.com, I can open that site in a separate script with

$oIE = _IECreate("http://www.freedomtaxation.com")
and AutoIt will report the same error consistently
C:\Program Files\AutoIt3\Beta\Include\IE.au3 (1026) : ==> The requested action with this object has failed.:

The site does redirect, but I have worked with other sites that redirect without a problem.

The other two errors are more troubling, because they seem to occur without any pattern (i.e. I cannot reproduce those errors on demand). Also although I have only posted three lines of error output, in the log once the error occurs in line 352, that error is just continually repeated and you have to kill the script to resolve the error condition.

The only "pattern" that I have observed, is that if I set the IE browser windows to be hidden, rather than visible, then the errors in 348 and 352 occur more frequently, but they still don't occur on the same URL's unlike the error in line 1026 which clearly has something to do with that particular site.

Can the error handler be configured differently either to produce more debugging info to help me isolate where the issue is occuring in my code?,

Or to provide less info so that I can make my script more "robust" and able to continue processing despite the error?

Thanks

VW

Share this post


Link to post
Share on other sites



Those errors look pretty odd. Are you using other COM related functions in your script? Realize that there can only be one COM error handler so it will trap any COM errors, not just those related to IE.

The error you get associated with _IECreate("http://www.freedomtaxation.com") alone is expected as IE.au3 treats certain types of COM errors as transient and retries to that your script does not abort. What you see in your log file may not be related to that at all however -- so long as you use _IEErrorHandlerRegister(), there are places that IE.au3 will deregister your error handler, register its own and then put yours back -- this is one of those places.

I'm suspicious that the RPC errors are not related to IE.au3

I suggest you add trace lines to your script or set positional context variables that you can write to your logfile so that you can better monitor what is executing when.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

I am not using any other COM related functions, but nonetheless I think you're right, I have been approaching these errors with the assumption that they're IE related errors and I've done some more testing and I am beginning to have doubts about that too.

I am going to turn off the error handler for the moment and see if I can isolate where these errors are occurring.

Thanks

VW

Share this post


Link to post
Share on other sites

Hi Dale,

Can you have a look at this, this code will produce the error in line 1026

#include <IE.au3>

$oIE = _IECreate("http://www.freedomtaxation.com")

$oLinks1 = _IELinkGetCollection ($oIE)
If @error = 0 Then
    $iNumLinks1 = @extended
EndIf

Thanks

VW

Share this post


Link to post
Share on other sites

Hi Dale,

Can you have a look at this, this code will produce the error in line 1026

#include <IE.au3>

$oIE = _IECreate("http://www.freedomtaxation.com")

$oLinks1 = _IELinkGetCollection ($oIE)
If @error = 0 Then
    $iNumLinks1 = @extended
EndIf

Thanks

VW

Well this is screwed up... the DOM is screwed up that is. There is something strange about this particular page that is confusing it. $oIE.document.links is returning an object with an objName of DispHTMLImg - on other pages it returns DispHTMLElementCollection. .length is not a valid property for DispHTMLImg!

The page has at least one serious HTML structure flaw... it has an opening <head> tag but has no closing </head>. If you run the W3C validator on it you'll see there are lots of problems... see here: validation results. The error has nothing to do with the redirect BTW.

I can't trap for unexpected errors like this or I'd double the size of the UDF again...

I suggest you inform the site authors and ask them to clean up their site.

You can also use _IEErrorHandlerRegister and you can trap for COM errors on your own and not have your script abort.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You can also use _IEErrorHandlerRegister and you can trap for COM errors on your own and not have your script abort.

I would like to do that, but when I use the current function (post #1) I get more errors reported, than when I do not use the function (which I can live with) but when I get that error in line 352 the error reporting goes nuts and effectively kills my script.

Is there a way that I can configure the error reporting, to only report an error once and then continue?

I have tried closing the IE instance using _IEQuit and killing the IE process, and none of those methods have been effective.

The ideal error handling situation would be:

- report the information that gets reported in the Console when an error occurs

- continue script processing (i.e. only the report the error condition once)

- I have a "main" for/next loop where I process the URL's and I would be happy to Continue that loop and move onto the next URL if it is possible to configure the error-handling in that manner

Would appreciate comments on what options I have.

Thanks

VW

Edited by VeeDub

Share this post


Link to post
Share on other sites

Without knowing specifically what is causing the errors it is difficult to provide further advise.

I would simply say that when the COM error handler is called, you get to make your own choice about what to do about the exception. You can decide in the error routine or you can return control to your script, examine @error and take action there -- you can ignore it, you can write it to a log, you can take a conditional branch or you can abort. It is all up to you.

Also note that the only routine in IE.au3 that traps and then may decide to retry after a COM error is _IELoadWait. If you use the $f_wait = False flag on any of the routines that call _IELoadWait you will have full control over handling all exceptions (although you will have to use your own logic to insure page readystate).

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Hi Dale,

I have finally managed to produce a script that will re-produce the 352 error about 1 in every 5 times that I run it.

Here's the code:

#include <IE.au3>

    _IELoadWaitTimeout(120000)
    
    $visible = 0
;   1 = visible, 0 = hidden 
        
    ConsoleWrite("Site 1" & @CRLF)
    $oIE = _IECreate("MortgageBrokersRegister.com",0,$visible,1,0)
    Sleep(5000)
    _IEQuit($oIE)
        
    ConsoleWrite("Site 2"& @CRLF)
    $oIE = _IECreate("QuoteMyFinance.com.au",0,$visible,1,0)
    Sleep(5000)
    _IEQuit($oIE)
    
    ConsoleWrite("Site 3"& @CRLF)
    $oIE = _IECreate("au.shopsdirect.com",0,$visible,1,0)
    Sleep(5000)
    _IEQuit($oIE)
    
    ConsoleWrite("Site 4"& @CRLF)
    $oIE = _IECreate("http://amogfs.com.au/",0,$visible,1,0)
    Sleep(5000)
    _IEQuit($oIE)

Here's the error output when it crashes out:

Site 1
Site 2
Site 3
C:\Program Files\AutoIt3\Include\IE.au3 (352) : ==> The requested action with this object has failed.: 
Until ($o_object.readyState = "complete" Or $o_object.readyState = 4) 
Until ($o_object.readyState ^ ERROR

Why did I chose these particular sites, they appeared in a log file that I was running when the script was running and it crashed on Site 4. Most of the time, when this script experiences an error, it is on Site 4. Although in this particular example the error occurred on Site 3.

If I run with the browser windows visible, no problem. If I run with the browser windows hidden, then there will be problems intermittently. Fortunately with this script (there must be something about these sites) the 352 error occurs far more regularly than I normally observe.

This script is consistent with the results that I have been experiencing generally, which is that when I am testing I run with browser windows visible, and I don't experience these errors (sometimes 348, mostly 352). When I think I have the code sorted out I prefer to run with the browser windows hidden so that I can do other stuff and just monitor the log files to see where the script is up to (which is pretty cool) until these intermittent errors started arising.

Hopefully you will get the same results as I am experiencing and can use this script to isolate the issue.

Thanks.

VW

Share this post


Link to post
Share on other sites

@VW - aer you registering your error handler with _IEErrorHandlerRegister???? If so, you should not be receiving that error in your error handler... _IELoadWait will shield you from those knowing that they are transient (it deregisters yours, registers the system error handler and puts yours back when it is done).

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

@VW - aer you registering your error handler with _IEErrorHandlerRegister???? If so, you should not be receiving that error in your error handler... _IELoadWait will shield you from those knowing that they are transient (it deregisters yours, registers the system error handler and puts yours back when it is done).

Dale

@Dale - when I register the error handler if I get an error in line 352 the error handler goes nuts and writes out the error message initially 30 or 40 times, and then when the next operation is performed maybe another 100 entries and so on.

This is the crux of the problem, if the error handler only wrote one message, and more importantly the script was able to continue on with it's processing then that would be fine. For other errors, the error-handling seems fine, you get a line reporting the error and script continues processing. Other errors are pretty rare though, the most commonly reported errors are 348 & 352, and 352 effectively kills the process.

I'll add the error handler to the test script and see if it reports bulk errors.

Thanks

VW

Share this post


Link to post
Share on other sites

Here's the code with the error handler:

#include <IE.au3>


;   Register custom error handler
    _IEErrorHandlerRegister ("MyErrHandler")

    _IELoadWaitTimeout(120000)
    
    $Activity_File = @ScriptDir & "error_352-log.txt"
    $visible = 0
;   1 = visible, 0 = hidden 
        
    ConsoleWrite("Site 1" & @CRLF)
    $oIE = _IECreate("MortgageBrokersRegister.com",0,$visible,1,0)
    Sleep(5000)
    _IEQuit($oIE)
        
    ConsoleWrite("Site 2"& @CRLF)
    $oIE = _IECreate("QuoteMyFinance.com.au",0,$visible,1,0)
    Sleep(5000)
    _IEQuit($oIE)
    
    ConsoleWrite("Site 3"& @CRLF)
    $oIE = _IECreate("au.shopsdirect.com",0,$visible,1,0)
    Sleep(5000)
    _IEQuit($oIE)
    
    ConsoleWrite("Site 4"& @CRLF)
    $oIE = _IECreate("http://amogfs.com.au/",0,$visible,1,0)
    Sleep(5000)
    _IEQuit($oIE)

;   Open some more sites
    For $c = 5 to 15
        ConsoleWrite("Site " & $c & @CRLF)
        $oIE = _IECreate("http://amogfs.com.au/",0,$visible,1,0)
        Sleep(5000)
        _IEQuit($oIE)
    Next    

    
Func MyErrHandler()
   ; Important: the error object variable MUST be named $oIEErrorHandler
    $ErrorScriptline = $oIEErrorHandler.scriptline
    $ErrorNumber = $oIEErrorHandler.number
    $ErrorNumberHex = Hex($oIEErrorHandler.number, 8)
    $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2)
    $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2)
    $ErrorSource = $oIEErrorHandler.Source
    $ErrorHelpFile = $oIEErrorHandler.HelpFile
    $ErrorHelpContext = $oIEErrorHandler.HelpContext
    $ErrorLastDllError = $oIEErrorHandler.LastDllError
    $ErrorOutput = ""
    $ErrorOutput = @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & " "
    $ErrorOutput &= "--> Error " & @CR
    $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & " "
    $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & " "
    $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & " "
    $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & " "
    $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & " "
    $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & " " 
    $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError & " "

    $Activity_Log = FileOpen($Activity_File,1)
    FileWriteLine($Activity_Log,$ErrorOutput)
    FileClose($Activity_Log)

    SetError(1)
    Return
EndFunc

The first time I ran this, the code stopped on 'Site 6' for about 10 minutes, did not report an error, and eventually I stopped the script.

After this I decided to re-install AutoIt in case there is a problem with my installation, I now get an error message about AU3Check each time I run the script (see separate post) but apart from that I have run this script a number of times and not a single error reported.

I think I'll wait until I get the AU3Check error fixed and then do some more testing, at this stage I'm unsure what to think, but perhaps there was some problem with my AutoIt install.

VW

Share this post


Link to post
Share on other sites

I ran the script a couple more times and then it hung on Site 4. So then I tried running it with windows visible, and it hung on Site 2.

The browser closed due to _IEQuit (after Site 1) and the browser window for Site 2 never appeared.

I normally have a Sleep(100) after each _IEQuit, which I didn't have in the test script, so I've added that in.

I also checked my other script, where I am having these errors and discovered that after one _IEQuit statement there was no Sleep statement, so I have added that in too.

Share this post


Link to post
Share on other sites

I cannot reproduce the errors you are seeing.

Please add the following to your script:

$__IEAU3Debug = True

This will force the display of COM errors trapped by the internal handler.

Let me know the results.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Dale,

Thanks for that, I have a feeling that the error has been caused by the missing Sleep statement after the _IEQuit.

I need to do some extended testing to confirm that, but since I've made that change I have not seen an error.

I have wasted a lot of time tracing this, which is my own fault for missing the Sleep statement (after the _IEQuit) in the first place, but it might be worth considering building in an automatic delay into the _IEQuit function, so that you if follow it with an _IECreate then there won't be a problem. For example

For $Sites = 0 to $Site_Count
$oIE = _IECreate("some url")
_IEQuit($oIE)
Sleep(100)   ; <--- My experience has been that this delay is necessary for reliable operation
Next

I appreciate your assistance and feedback, it helps to have someone to bounce ideas off.

Cheers,

VW

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0