Custom error handling

Top  Previous  Next

 

--catch err=function

 

You may add custom error handling functions which will catch script licensing errors. The error handler is a function which accepts two parameters:

 

error_handler( code , message )

 

You may use any name for this function. Also you may have different functions for different script errors. The first argument is the error code. The second one  is the default error message. To set a custom error handler use --catch option for the rubyencoder command:

 

>rubyencoder --catch err=function myscript.rb

 

Where "err" is one of the predefined constants and "function" is an error handler function name.

 

Err tag

Returned code

Default message

ERR_LICENSE

01,02,03,

04,05

script cannot run on this machine

(code indicates a reason: 01-IP, 02-domain, 03-MAC address,

04-machine ID, 05-remote verification URL locking)

ERR_EXTLICCRC

06

script license is invalid

ERR_EXPIRED

09

script has expired

ERR_EXTLIC

13

script requires license file to run

ERR_OFFLINE

20

script requires an internet connection to run

ERR_ALL

-

-

 

ERR_ALL is a special value to specify "one-for-all" error handler function.

 

The custom error handler function should be defined before an error may occur. The best place for it is in "custom header" code as it's loaded before any license checking is done and so the error handler will be always available if defined there. But you may also define a custom error handler function in another encoded file which will be run before the script which may cause a license error. Don't put any passwords or secret data if you use a "custom header" code for defining an error handler as this code is stored unencoded.

 

Example:

 

Encode ruby script with a custom header containing definition of my_err_handler() function. Please note additional back slashes ( \ ) are used to quote special character in command line.

 

>rubyencoder -p "def my_err_handler(code,msg); printf \"My error handler caught error code %d with a message '%s'\\n\", code, msg; end;" --catch ERR_ALL=my_err_handler --external script.lic --projid Fg3161jd --projkey 826Gdb31 hello.rb

 

The encoded script will have the defined code as unencoded in the beginning:

 

# RubyEncoder v1.0                                                                                

def my_err_handler(code,msg); printf "My error handler caught error code %d with a message '%s'\n",

code, msg; end;                                                                                    

_d = _d0 = File.expand_path(File.dirname(__FILE__)); while 1 do _f = _d + '/rgloader/loader.rb'; bre

ak if File.exist?(_f); _d1 = File.dirname(_d); if _d1 == _d then raise "Ruby script '"+__FILE__+"' i

s protected by RubyEncoder and requires the RubyEncoder loader. Please visit the http://www.rubyenco

der.com/loaders/ RubyEncoder site to download the required loader and unpack it into '"+_d0+"/rgload

er/' directory to run this protected script."; break; else _d = _d1; end; end; require _f; RGLoader:

:load('AAEAAAAEoAAAAIAAAAAA/y7C/NTZP8FnCp00d+uHwMSVgcicoaW6ERaCNJzTN2xah6H+6o9f2eGRGZuRBc9AjPFIowkPt

+ZUc2o6qTmfb4Dk6gJ3OsVgI20+Yzju02WIv3pGK3UDOMw+MFuXAIp7+8AL1Yy4FLawYTxZqzQTnsCQgOFObFkJhkidkqAHHKdyf

Y7Fy0N1IhlqOMT1AWwOan2WIpMkbwbxl3vykcvUpncSAAAAYAAAAPwjqwCB2fc7tjHyItPnu1hcuoPtNMLr51XrpsB9d1KJVCO+W

IrJB4Y3O1HCvzSDsC7dJ/Ak5LMBV/fVHQgOV2Is3B2/SgalIdFcllJ6ImqOJGBQDpAjBya977eTnLMDwAAAAAA=');

 

Now a test run without the required license file:

 

>ruby hello.rb

 

My error handler caught error code 9 with a message 'RubyEncoder Loader - This script has expired. Contact the script author about this problem. Error code [09]'