Skip to content

$iErr = $_WD_ERROR_Exception and re-ordering $_WD_ERROR_* #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mlipok opened this issue Mar 14, 2023 · 26 comments · Fixed by #448
Closed

$iErr = $_WD_ERROR_Exception and re-ordering $_WD_ERROR_* #438

mlipok opened this issue Mar 14, 2023 · 26 comments · Fixed by #448

Comments

@mlipok
Copy link
Contributor

mlipok commented Mar 14, 2023

Feature request

Is your feature request related to a problem?

there is many places where UDF uses such template:

	If $iErr = $_WD_ERROR_Success Then
		.....
	Else
		$iErr = $_WD_ERROR_Exception
	EndIf
	Return SetError(__WD_Error($sFuncName, $iErr), 0, $sValue)
EndFunc

IMO this is wrong,

At least this enums should be passed to the main script

$_WD_ERROR_SocketError
$_WD_ERROR_SendRecv
$_WD_ERROR_SessionInvalid
$_WD_ERROR_ContextInvalid

IMO they are main/general errors which can occrus when webdriver, browser, session is closed, and in such case reporting just: $_WD_ERROR_Exception is a big a misunderstanding/mistake/oversight, even if they came from some internal processing.

Describe the solution you'd like

we should reorder enums $WD_ERROR* like this:

Global Enum _
		$_WD_ERROR_Success = 0, _ ; No error
		$_WD_ERROR_GeneralError, _ ; General error
		$_WD_ERROR_NotSupported, _ ; When user try to use unsupported browser or capability
		$_WD_ERROR_AlreadyDefined, _ ; Capability previously defined
		$_WD_ERROR_SocketError, _ ; No socket
		$_WD_ERROR_SendRecv, _ ; Send / Recv Error
		$_WD_ERROR_SessionNotCreated, _ ; Session not created
		$_WD_ERROR_ContextInvalid, _ ; Invalid browsing context
		$_WD_ERROR_SessionInvalid, _ ; Invalid session ID was submitted to webdriver
		$_WD_ERROR_UserAbort, _ ; In case when user abort when @error occurs and $_WD_ERROR_MSGBOX was set
		$_WD_ERROR_Exception, _ ; Exception from web driver
		$_WD_ERROR_InvalidDataType, _ ; Invalid data type (IP, URL, Port ...)
		$_WD_ERROR_InvalidValue, _ ; Invalid value in function-call
		$_WD_ERROR_InvalidArgue, _ ; Invalid argument in function-call
		$_WD_ERROR_Timeout, _ ; Connection / Send / Recv timeout
		$_WD_ERROR_NoMatch, _ ; No match for _WDAction-find/search _WDGetElement...
		$_WD_ERROR_NoAlert, _ ; No alert present when calling _WD_Alert
		$_WD_ERROR_NotFound, _ ; File or registry key not found
		$_WD_ERROR_RetValue, _ ; Error echo from Repl e.g. _WDAction("fullscreen","true") <> "true"
		$_WD_ERROR_InvalidExpression, _ ; Invalid expression in XPath query, CSSSelector query or RegEx
		$_WD_ERROR_ElementIssue, _ ; Problem interacting with element (click intercepted, etc)
		$_WD_ERROR_UnknownCommand, _ ; Unknown command submitted to webdriver
		$_WD_ERROR_FileIssue, _ ; Errors related to WebDriver EXE File
		$_WD_ERROR_Javascript, _ ; Javascript error
		$_WD_ERROR__COUNTER ; Defines row count for $aWD_ERROR_DESC

to have possiiblity to use code like this:

	If $iErr = $_WD_ERROR_Success Then
		.....
	ElseIf $iErr > $_WD_ERROR_Exception Then
		$iErr = $_WD_ERROR_Exception
	EndIf
	Return SetError(__WD_Error($sFuncName, $iErr), 0, $sValue)
EndFunc

Describe alternatives you've considered

we can create separate internal function which will check desired cases and set $iErr accordingly.

Additional context

none

@mlipok
Copy link
Contributor Author

mlipok commented Mar 14, 2023

I also propose to add new $_WD_ERROR_InternalProcessing which I would like to use for some complex function like: _WD_FrameList and _WD_LocateElement

Global Enum _
		$_WD_ERROR_Success = 0, _ ; No error
		$_WD_ERROR_GeneralError, _ ; General error
		$_WD_ERROR_NotSupported, _ ; When user try to use unsupported browser or capability
		$_WD_ERROR_AlreadyDefined, _ ; Capability previously defined
		$_WD_ERROR_SocketError, _ ; No socket
		$_WD_ERROR_SendRecv, _ ; Send / Recv Error
		$_WD_ERROR_SessionNotCreated, _ ; Session not created
		$_WD_ERROR_ContextInvalid, _ ; Invalid browsing context
		$_WD_ERROR_SessionInvalid, _ ; Invalid session ID was submitted to webdriver
		$_WD_ERROR_UserAbort, _ ; In case when user abort when @error occurs and $_WD_ERROR_MSGBOX was set
		$_WD_ERROR_Exception, _ ; Exception from web driver
		$_WD_ERROR_InternalProcessing, _ ; The error comes from Internal processing
		$_WD_ERROR_InvalidDataType, _ ; Invalid data type (IP, URL, Port ...)
		$_WD_ERROR_InvalidValue, _ ; Invalid value in function-call
		$_WD_ERROR_InvalidArgue, _ ; Invalid argument in function-call
		$_WD_ERROR_Timeout, _ ; Connection / Send / Recv timeout
		$_WD_ERROR_NoMatch, _ ; No match for _WDAction-find/search _WDGetElement...
		$_WD_ERROR_NoAlert, _ ; No alert present when calling _WD_Alert
		$_WD_ERROR_NotFound, _ ; File or registry key not found
		$_WD_ERROR_RetValue, _ ; Error echo from Repl e.g. _WDAction("fullscreen","true") <> "true"
		$_WD_ERROR_InvalidExpression, _ ; Invalid expression in XPath query, CSSSelector query or RegEx
		$_WD_ERROR_ElementIssue, _ ; Problem interacting with element (click intercepted, etc)
		$_WD_ERROR_UnknownCommand, _ ; Unknown command submitted to webdriver
		$_WD_ERROR_FileIssue, _ ; Errors related to WebDriver EXE File
		$_WD_ERROR_Javascript, _ ; Javascript error
		$_WD_ERROR__COUNTER ; Defines row count for $aWD_ERROR_DESC

@Danp2
Copy link
Owner

Danp2 commented Mar 14, 2023

we should reorder $WD_ERROR* to have possiiblity to use code like this:

The code you posted following this line is exactly the same as the code that you indicated is wrong. Please correct this to remove any confusion.

@Danp2
Copy link
Owner

Danp2 commented Mar 14, 2023

I also propose to add new $_WD_ERROR_InternalProcessing which I would like to use for some complex function like: _WD_FrameList and _WD_LocateElement

Can you elaborate on how you would use this in each of these functions? Please be specific.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 14, 2023

we should reorder $WD_ERROR* to have possiiblity to use code like this:

The code you posted following this line is exactly the same as the code that you indicated is wrong. Please correct this to remove any confusion.

OP edited

@mlipok
Copy link
Contributor Author

mlipok commented Mar 14, 2023

I also propose to add new $_WD_ERROR_InternalProcessing which I would like to use for some complex function like: _WD_FrameList and _WD_LocateElement

Can you elaborate on how you would use this in each of these functions? Please be specific.

comment to enums says

$_WD_ERROR_Exception, _ ; Exception from web driver

and it should comes only from
__WD_Post/__WD_Delete/__WD_Get and specifically from __WD_DetectError

so focusing on _WD_FrameList I would like to change:

	Local Const $sElement_CallingFrameBody = _WD_ExecuteScript($sSession, "return window.document.body;", Default, Default, $_WD_JSON_Element)
	If Not @error Then
		$vResult = __WD_FrameList_Internal($sSession, 'null', '', False, $_WD_DEBUG_Saved)
	EndIf
	#Region - post processing
	If @error Then
		$iErr = $_WD_ERROR_GeneralError
	Else

to:

	Local Const $sElement_CallingFrameBody = _WD_ExecuteScript($sSession, "return window.document.body;", Default, Default, $_WD_JSON_Element)
	If Not @error Then
		$vResult = __WD_FrameList_Internal($sSession, 'null', '', False, $_WD_DEBUG_Saved)
		$iErr = @error
	EndIf
	#Region - post processing
	If $iErr Then
		If $iErr > $_WD_ERROR_Exception Then 
			$iErr = $_WD_ERROR_InternalProcessing
		Endif
	Else

@Danp2
Copy link
Owner

Danp2 commented Mar 14, 2023

comment to enums says

$_WD_ERROR_Exception, _ ; Exception from web driver

and it should comes only from __WD_Post/__WD_Delete/__WD_Get and specifically from __WD_DetectError

Comments are informational only. 😉 I would need to research before making decision on this.

so focusing on _WD_FrameList I would like to change to:

		If $iErr > $_WD_ERROR_Exception Then 
			$iErr = $_WD_ERROR_InternalProcessing
		Endif

Sorry, but I'm having trouble making sense of this. These are the questions I have thus far --

  • What determines when a specific error code should come before / after $_WD_ERROR_Exception in the enum?
  • Why would you want to return $_WD_ERROR_InternalProcessing to the calling script?
  • Aren't you just substituting $_WD_ERROR_InternalProcessing for $_WD_ERROR_Exception as a way to return multiple error conditions under a single error code?

I initially envisioned that you wanted to use $_WD_ERROR_InternalProcessing as a way to pass errors from an internal function (ie: __WD_FrameList_Internal) to it's calling function (ie: __WD_FrameList), but that clearly isn't your intention here. 🤔

@mlipok
Copy link
Contributor Author

mlipok commented Mar 14, 2023

Ok we can forget about $_WD_ERROR_InternalProcessing

What about reordering, and passing all main errors ?

@Danp2
Copy link
Owner

Danp2 commented Mar 14, 2023

Please answer my earlier question --

What determines when a specific error code should come before / after $_WD_ERROR_Exception in the enum?

@mlipok
Copy link
Contributor Author

mlipok commented Mar 18, 2023

comment to enums says

$_WD_ERROR_Exception, _ ; Exception from web driver

and it should comes only from __WD_Post/__WD_Delete/__WD_Get and specifically from __WD_DetectError

Comments are informational only. 😉 I would need to research before making decision on this.

not only comments, this following part also says:

Global Const $aWD_ERROR_DESC[$_WD_ERROR__COUNTER] = [ _
...
		"Webdriver Exception", _
...

@mlipok
Copy link
Contributor Author

mlipok commented Mar 18, 2023

btw.
i did some test by modifying wd_demo.au3:

	ConsoleWrite("> wd_demo.au3: _WD_Startup" & @CRLF)
	Local $iWebDriver_PID = _WD_Startup()
	If _RunDemo_ErrorHander((@error <> $_WD_ERROR_Success), @error, @extended, $iWebDriver_PID, $sSession) Then Return

	ConsoleWrite("> wd_demo.au3: _WD_CreateSession" & @CRLF)
	MsgBox($MB_TOPMOST, "", ' BEFORE _WD_CreateSession - please close WebDriver Console window')
	$sSession = _WD_CreateSession($sCapabilities)
	MsgBox($MB_TOPMOST, "", ' AFTER _WD_CreateSession')
	Exit

my result was:

_WD_Startup ==> Success [0]
> wd_demo.au3: _WD_CreateSession
__WD_Post ==> Send / Recv error [6] : HTTP status = 0
_WD_CreateSession ==> Webdriver Exception [10]

and my question are:

What was a reason for _WD_CreateSession() to change $_WD_ERROR_SendRecv >> $_WD_ERROR_Exception ?

Do any other function return $_WD_ERROR_SendRecv ?

@Danp2
Copy link
Owner

Danp2 commented Mar 18, 2023

What was a reason for _WD_CreateSession() to change $_WD_ERROR_SendRecv >> $_WD_ERROR_Exception ?

I think the idea was to limit the number of error codes that the calling routine would need to handle. Do you think a user script would need to distinguish between $_WD_ERROR_InvalidValue, $_WD_ERROR_SendRecv, $_WD_ERROR_SocketError, etc? If Yes, then please provide a detailed description of when this would be beneficial.

Do any other function return $_WD_ERROR_SendRecv ?

It's certainly possible if the function simply returns the error code coming from __WD_Get/Put/Delete without overriding it.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 20, 2023

firstly Capabilities must be created - this following @error are related to creating capabilities

$_WD_ERROR_NotSupported, _ ; When user try to use unsupported browser or capability
$_WD_ERROR_AlreadyDefined, _ ; Capability previously defined

then Session must be created - this following @error are related to creating scession

$_WD_ERROR_SessionNotCreated, _ ; Session not created
$_WD_ERROR_FileIssue, _ ; Errors related to WebDriver EXE File

this following @error are related to communication issues between UDF and WebDriver

$_WD_ERROR_SocketError, _ ; No socket
$_WD_ERROR_SessionInvalid, _ ; Invalid session ID was submitted to webdriver
$_WD_ERROR_ContextInvalid, _ ; Invalid browsing context
$_WD_ERROR_UnknownCommand, _ ; Unknown command submitted to webdriver
$_WD_ERROR_Exception, _ ; Exception from web driver

All other @error are related in some way to USER actions or ENV

@mlipok
Copy link
Contributor Author

mlipok commented Mar 20, 2023

I think the idea was to limit the number of error codes that the calling routine would need to handle.

that's what I thought

Do you think a user script would need to distinguish between $_WD_ERROR_InvalidValue, $_WD_ERROR_SendRecv, $_WD_ERROR_SocketError, etc?

Yes.

If Yes, then please provide a detailed description of when this would be beneficial.

When user had already properly created connection, and all was working fine be first few minutes of proccessing then something happen and user get error $_WD_ERROR_Exception how he should check/know what the issue was ?

@mlipok
Copy link
Contributor Author

mlipok commented Mar 20, 2023

For example I intentionally removed $_WD_ERROR_Exception from _WD_FrameList() to get this possibilities:

__WD_FrameList_Internal ==> Invalid Browsing Context [17] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/22"
__WD_FrameList_Internal ==> Invalid Browsing Context [17] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/23"
__WD_FrameList_Internal ==> Webdriver Exception [10] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/24"
__WD_FrameList_Internal ==> Invalid session ID [16] : Parameters:    Level=null    IsHidden=False	Information: Error occurred on "null" level when trying to check attributes of subframe "null/25"
_WD_FrameList ==> Invalid session ID [16 / 0] : Parameters:    ReturnAsArray=True	Information: Was not able to check "calling frame".

As you see that $_WD_ERROR_Exception occurs somwhere in the middle, but finally last error is Invalid session ID and you have information about real reason what goes wrong.

@Danp2
Copy link
Owner

Danp2 commented Mar 20, 2023

From a debugging perspective, I agree that having the correct error code is essential, and we already have that in the logs when the correct debugging level is set. My question was regarding user scripts and whether the script would benefit by having multiple error codes returned.

After calling _WD_FrameList, how would the user script respond differently if it received error $_WD_ERROR_SessionInvalid vs $_WD_ERROR_Exception?

@mlipok
Copy link
Contributor Author

mlipok commented Mar 20, 2023

Normally I would build a wrapper for checking error which will show some kind of MSGBOX dialog with error information like:
Your WebDriver session is invalid , check if ..... and contact your IT support.
or
Your WebDriver session is invalid , check if FireFox is still working if not - start the process again.

or I would just reinitialize connection.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 20, 2023

I have few script that in case of errors are trying to repeat processsing, but as so far I never checks for the case if session is still valid, or if other connection issues occurs.

In other words, I have a feelling that currently when you get $_WD_ERROR_Exception, _ ; Exception from web driver this mean that you should check for any possible errors like:

$_WD_ERROR_SocketError, _ ; No socket
$_WD_ERROR_SessionInvalid, _ ; Invalid session ID was submitted to webdriver
$_WD_ERROR_ContextInvalid, _ ; Invalid browsing context
$_WD_ERROR_UnknownCommand, _ ; Unknown command submitted to webdriver

so after getting $_WD_ERROR_Exception you should call _WD_CheckContext to be sure what is going on.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 20, 2023

after getting $_WD_ERROR_Exception you should call _WD_CheckContext to be sure what is going on.

Am I right ?
How are you handling these bugs in your applications?

@Danp2
Copy link
Owner

Danp2 commented Mar 20, 2023

How these errors (not bugs 😛) are handled in a script is a design decision, so there isn't a right or wrong answer here.

@Danp2
Copy link
Owner

Danp2 commented Mar 20, 2023

firstly Capabilities must be created - this following @error are related to creating capabilities

As I mentioned before, comments are informational only and shouldn't be interpreted as absolute.

For example, the comments associated to $_WD_ERROR_NotSupported are When user try to use unsupported browser or capability. But if you examine _WD_ElementStyle, you will see that this error code is used to indicate an unsupported combination of parameters.

@Danp2
Copy link
Owner

Danp2 commented Mar 20, 2023

To summarize your request --

  • UDFs should return the actual error codes from internal routines rather than a singular code such as $_WD_ERROR_Exception

    This can certainly be done, but I'm thinking it should default to the current behavior. An option could be added to _WD_Option to allow the expanded error codes to be enabled.

  • Reorder $_WD_ERROR enum to allow for further processing based upon enum value

    I'm not sure that this is feasible / desirable. You mentioned an alternative that used an internal function to check desired cases and set $iErr accordingly. I would suggest pursuing this option.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 21, 2023

firstly Capabilities must be created - this following @error are related to creating capabilities

As I mentioned before, comments are informational only and shouldn't be interpreted as absolute.

For example, the comments associated to $_WD_ERROR_NotSupported are When user try to use unsupported browser or capability. But if you examine _WD_ElementStyle, you will see that this error code is used to indicate an unsupported combination of parameters.

we should review these comments and change them as they are currently causing confusion

@mlipok
Copy link
Contributor Author

mlipok commented Mar 21, 2023

  • UDFs should return the actual error codes from internal routines rather than a singular code such as $_WD_ERROR_Exception
    This can certainly be done, but I'm thinking it should default to the current behavior. An option could be added to _WD_Option to allow the expanded error codes to be enabled.

I'm fine with this. If you want and if you find some spare time can you provide PR ?

  • Reorder $_WD_ERROR enum to allow for further processing based upon enum value
    I'm not sure that this is feasible / desirable. You mentioned an alternative that used an internal function to check desired cases and set $iErr accordingly. I would suggest pursuing this option.

Thanks. I will follow your advice.

@mlipok
Copy link
Contributor Author

mlipok commented Mar 21, 2023

In other words, I have a feelling that currently when you get $_WD_ERROR_Exception, _ ; Exception from web driver this mean that you should check for any possible errors like:

$_WD_ERROR_SocketError, _ ; No socket
$_WD_ERROR_SessionInvalid, _ ; Invalid session ID was submitted to webdriver
$_WD_ERROR_ContextInvalid, _ ; Invalid browsing context
$_WD_ERROR_UnknownCommand, _ ; Unknown command submitted to webdriver

so after getting $_WD_ERROR_Exception you should call _WD_CheckContext to be sure what is going on.

I wonder if you anywhere had a need to check after the error $_WD_ERROR_Exception to check/call _WD_CheckContext ?

@Danp2
Copy link
Owner

Danp2 commented Mar 21, 2023

I wonder if you anywhere had a need to check after the error $_WD_ERROR_Exception to check/call _WD_CheckContext ?

No, this isn't something that I've done to date.

we should review these comments and change them as they are currently causing confusion

It would be simple to change that specific comment to "Unsupported option". Which others do you find confusing?

@mlipok
Copy link
Contributor Author

mlipok commented Mar 21, 2023

So finally we have

  • UDFs should return the actual error codes from internal routines rather than a singular code such as $_WD_ERROR_Exception
    This can certainly be done, but I'm thinking it should default to the current behavior. An option could be added to _WD_Option to allow the expanded error codes to be enabled.

I'm fine with this. If you want and if you find some spare time can you provide PR ?

And #447

@Danp2 Danp2 linked a pull request Mar 25, 2023 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants