Jump to content

Seeking ways to stop the 'clang'


qwert
 Share

Recommended Posts

Under the general heading of 'There's gotta be a way', I've been exploring possible solutions to intercept the script abort message and, instead of the harsh 'Clang and X' abort message, display a reasonable message like the following:

"An unforeseen error has occurred that prevents this program from continuing.  It will now close without completing the requested operation."

Here's a UDF that's complex that I could never consider adding it to a production script.  My needs just aren't that complicated.  I applaud the intent, but think it needs great simplification for wide use.

Here's a simpler method that only removes 'AutoIt' from the heading on the message.  As shown below, I've modified it for my immediate use to give a one-step-better message to the user (no Clang ... no 'X').  For some reason, $sText cannot be altered, but $sTitle can.  0x00000030 is the code for the "!" message type.

My point is this: production scripts are thoroughly tested.  Any error condition that occurs is due to some condition outside of the realm of typical operation and will be rare.  Any such error needs to be handled graciously and without alarming the user.  Clang+X doesn't meet that need.

The very best solution would a universal one that could be invoked at a macro level (like #RequireAdmin) or maybe with an umbrella call (like _GDIPlus_Startup).

I hope that I've missed something and that this already exists, but I haven't found it.

Thanks in advance for any help.
 

AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint")
Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType)
    Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _
            "hwnd", $hWnd, _
            "wstr", $sText, _
            "wstr", StringReplace($sTitle, "AutoIt", "Error has occurred: Invalid ZIP file"), _
            "uint", 0x00000030)
    If @error Or Not $aCall[0] Then Return 0
    Return $aCall[0]
EndFunc

Interim solution.png

For reference: msdn link

Link to comment
Share on other sites

You will need to study the example code and you should be able to get an idea of what you need to do In order to deal with it or just bypass it and log it. Whatever your needs are

The examples are really nice and demonstrate just what you were trying to do

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

After several adjustments to the RegExp (more than I will admit to), the following statements produce the message shown below.

I'll welcome any simplifying adjustment or suggestions for a different method.  But this method appears to meet my immediate requirement.

AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint")
Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType)
    Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _
            "hwnd", $hWnd, _
            "wstr", StringRegExpReplace(StringRegExpReplace($sText, "\([^)]*\)", ""), "(.*)\bError\b(.*)", "An unsupported file condition has been encounted that prevents this program from continuing.  It will now close without completing the requested operation."), _
            "wstr", StringReplace($sTitle, "AutoIt", "Invalid ZIP file"), _
            "uint", 0x00000030)
    If @error Or Not $aCall[0] Then Return 0
    Return $aCall[0]
EndFunc

Interim result.PNG

Link to comment
Share on other sites

I've made a change to the RegExp to avoid modifying any message message text with the word 'Error'.  It now modifies only those with 'Error: '.

StringRegExpReplace(StringRegExpReplace($sText, "\([^)]*\)", ""), "(.*)\bError: \b(.*)", "An unsupported file condition has been encounted that prevents this program from continuing.  It will now close without completing the requested operation."), _

Thanks to ViciousXUSMC for the link to RegEx101 dot com, where I was able to confirm the improved RegExp.

Edited by qwert
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...