Robotic Process Automation (RPA)

Robotic Process Automation (RPA)

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
  • 1.  What to do when a command inside a handle error routine fails?

    Posted 08/22/22 04:50 PM
    Hello everyone. Let's supose this:

    I have a script which sends an email. If something fails with the command emailSend (1 of 50 times fails by connection problems), an error routine is called. In this error routine handler I have another emailSend command to notify the error details, but if the connection fails again inside the error handler, the script just stops.

    • Is there any workaround to solve or handle errors inside an error handler routine?  
    • What can I do to retry sending the email?

    Thank you.

    ------------------------------
    Jose Luis Rodriguez Gonzalez
    ------------------------------


  • 2.  RE: What to do when a command inside a handle error routine fails?

    Posted 08/23/22 08:49 AM
    Edited by Vinicius Marques 08/23/22 11:03 AM
    Hi Jose,

    I find it easier to use another script when handling issues like these. When the executeScript command is configured to handle errors, you can easily check for the status of execution of the whole script and create a retry mechanism based on the status. In your case, you would use the "send email" functionality inside the child script.


    Here is an example of how to do it already with the retry mechanism:
    defVar --name count --type Numeric
    defVar --name success --type Boolean
    defVar --name errorMessage --type String
    defVar --name errorLineNumber --type Numeric
    defVar --name errorRoutineName --type String
    defVar --name error --type Error
    for --variable ${count} --from 1 --to 5 --step 1
    	executeScript --handleError  --name Teste --comment "Supresses errors that might happen inside the executed script. You can validate the status through the output variables." errorMessage=errormessage errorLineNumber=linenumber errorRoutineName=errorsubname error=error success=value
    	if --left "${success}" --operator "Is_True" --comment "If true, then should stop retrying"
    		break
    	endIf
    next
    
    if --left "${success}" --operator "Is_True" --negate  --comment "If true, then child script was executed sucessfuly"
    	logMessage --message "Execution of script failed even after multiple attempts. Error: ${error}" --type "Error"
    endIf
    


    ------------------------------
    Vinicius Marques
    ------------------------------



  • 3.  RE: What to do when a command inside a handle error routine fails?

    Posted 08/23/22 10:49 AM
    Hi Vinicius,

    That is great. Thank you very much.

    ------------------------------
    Jose Luis Rodriguez Gonzalez
    ------------------------------



  • 4.  RE: What to do when a command inside a handle error routine fails?

    Posted 08/23/22 11:55 AM
    Hi Jose Luis,

    I would use more than one error-handling subroutine. If connecting to the email provider fails, trying to send an email on the error-handling subroutine will also fail; and when a command fails in the error-handling subroutine, you can't recover. Thus, you need to separate concerns.

    The following snippet shows an example; you can copy the code, paste the code on your RPA Studio and study the example:

    defVar --name emailPasword --type SecureString
    defVar --name imapConnection --type EmailConnection
    defVar --name emails --type List --innertype String
    defVar --name errorMessage --type String
    // This script does not work: it is intended as an example of how to deal with multiple error contexts.
    // You can use onError multiple times. onError is a scope-based command: it wraps the commands of the subroutine, and inner subroutines, he is in.
    
    // Imagine your script does a bunch of stuff. Eventually, the script tries to send an email.
    
    onError --label handleGeneralError --comment "This Handle Error deals with any errors in a generic way."
    
    goSub --label SendEmail
    beginSub --name handleGeneralError
    // Handle any errors in a generic way: log and try to send email.
    setVar --name "${errorMessage}" --value "An error occured:\r\n\r\n${wdg:error}"
    logMessage --message "${errorMessage}" --type "Error"
    imapConnect --mailhost "example.imap.com" --mailport 993 --usessl  --UseConnectionToSend  --smtpcredentials  --smtphost "example.smtp.com" --smtpport 443 --smtpusername "email@example.com" --smtppassword "${emailPasword}" --smtpusessl  --mailusername "email@example.com" --mailpassword "${emailPasword}" imapConnection=value
    emailSend --connection ${imapConnection} --to ${emails} --from "email@example.com" --bodytype "Text" --body "${errorMessage}"
    emailDisconnect --connection ${imapConnection}
    endSub
    beginSub --name SendEmail
    // Now, this is a crucial part of the process. If this task fails, trying to send the email again will be redundant: it already failed. So you can use a new onError here to redirect to another error-handling approach.
    
    onError --label handleErrorSendingEmail
    
    imapConnect --mailhost "example.imap.com" --mailport 993 --usessl  --UseConnectionToSend  --smtpcredentials  --smtphost "example.smtp.com" --smtpport 443 --smtpusername "email@example.com" --smtppassword "${emailPasword}" --smtpusessl  --mailusername "email@example.com" --mailpassword "${emailPasword}" imapConnection=value
    emailSend --connection ${imapConnection} --to ${emails} --from "email@example.com" --bodytype "Text" --body "\"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\""
    emailDisconnect --connection ${imapConnection}
    endSub
    beginSub --name handleErrorSendingEmail
    // Handle error related to sending emails. In here, trying to send the email again is redundant: it already failed. So what you could do is use a different error-handling approach. In this example, the script logs the error in the local log file, in the cloud, and also as a custom log file.
    setVar --name "${errorMessage}" --value "An error occured:\r\n\r\n${wdg:error}"
    logMessage --message "${errorMessage}" --type "Error"
    writeToFile --value " ${errorMessage}" --file "a/folder/where/you/store/logs.txt" --encoding "Default"
    endSub​
    ​​

    ------------------------------
    Gabriel Sanchez
    ------------------------------