Procscript

Error Handling

App Builder & Automation Expert

Stay Updated with ProcFu!

Subscribe to our newsletter for the latest tips, updates, and automation insights.

Subscribe Now

If a function or code block encounters an error, an error message is recorded in the logs. You can review these logs by visiting: https://procfu.com/account/logs/

For logs specific to data synchronization tasks, they are stored directly within the respective sync's records.

Custom Error Handling

To override the default error behavior, you can define your own error handler function. This allows you to control the outcome when a script fails, such as returning a specific value and avoiding error logs.

To illustrate, invoking a non-existent script via the call_pf_script function typically results in an error which will be logged.

script="UNKNOWN SCRIPT NAME TO CAUSE ERROR";
payload="{}"
return call_pf_script(script,payload)   

//ERROR: RUNTIME EXCEPTION: script not found: UNKNOWNSCRIPTNAMETOCAUSEERROR.pf on line 6

To customize this behavior and display a specific error message, you can implement additional code. With this modification, the error message will be replaced with "Custom Error Message" instead of the default message. And this message will not be logged.

function custom_error_handler(error_message, line) {
    yield "Custom Error Message"; 
}
ini_set("error_handler", "custom_error_handler");

script="UNKNOWN SCRIPT NAME TO CAUSE ERROR";
payload="{}"
return call_pf_script(script,payload)  

//The system shows "Custom Error Message"
In the mentioned scenario, the error handler function employs yield instead of return to send back a value. This approach is chosen because the function aims to override the standard return mechanism, allowing it to pass a value directly to the calling process and halt further execution.

Reset Custom Error Handler

When you need to ignore certain errors selectively while keeping the system's default exception-throwing behavior for others, you can reset the error handler to its original functionality. This reset is done by using ini_set("error_handler", false), which switches the error handling back to default, enabling the system to show actual error messages again.

function custom_error_handler(error_message, line) {
    yield "Custom Error Message"; 
}
ini_set("error_handler", "custom_error_handler");

script="UNKNOWN SCRIPT NAME TO CAUSE ERROR";
payload="{}"
return call_pf_script(script,payload)  

// The system shows "Custom Error Message"

// Resetting to the default error handler
ini_set("error_handler", false)
// Any subsequent errors will trigger the default exception mechanism

Conditional Error Management

You can customize your error handler to react differently depending on the error type. This allows you to show specific error messages for different scenarios or choose not to show a message for some errors.

function custom_error_handler(error_message, line) {
    if(stristr(error_message, "count")){
        yield "Count Issue" // Custom message for count-related errors
    }
    if(stristr(error_message, "invalid")){
        // Do not display any message for invalid-related errors
    }
}
ini_set("error_handler", "custom_error_handler");

script="UNKNOWN SCRIPT NAME TO CAUSE ERROR";
payload="{}"
return call_pf_script(script,payload)  

Manually Triggering Error Messages

In ProcScript, you can interrupt the execution of code at any point by using the throw keyword along with an error message. For instance: throw "Stop now".

Love using ProcFu Guide?

Share your testimonial and let us know how ProcFu has helped you.

Share Your Testimonial

Built with ❤️ by Thaha for the Community