Error Functions
A set of custom functions for handling errors in FileMaker solutions.
Introduction
This set of custom functions provides a standardized approach to error handling in FileMaker solutions. Instead of dealing with raw error codes, these functions create and manipulate structured JSON error objects that contain detailed information about errors, making them easier to track, log, and handle.
These functions are part of the errorCfx repository from Proof+Geist, available as open source under the MIT license.
The error objects typically include:
code: The numeric error codetext: A human-readable description of the errorscriptName: The name of the script where the error occurredscriptStep: The specific script step that generated the errorlineNumber: Line number in the script (when available)environment: Context information about the environment
Dependencies
These error functions rely on the following miscellaneous utility functions:
getScriptEnvironment- Provides system and script context informationJSON.isValid- Validates JSON formatnull- Returns a proper null value
Functions
error.GetCode(errorObject)
Description:
Returns the error code from a given error object. Returns 0 if there is no error, or the numeric error code if an error exists.
Parameters:
errorObject: An error object as JSON
Return:
- The numeric error code (
0if no error)
Example:
error.GetLast(customText)
Bug
Todo: Fix in source code
Description:
Returns an error object based on the information in FileMaker's error flags. If the LastError flag is set to 5499, it will return the custom error object found on line 4 of the LastErrorDetail flag.
Parameters:
customText(optional): Replaces the default error message
Dependencies:
error.Text- For error message lookupJSON.isValid- For validating custom error JSONnull- For null handlinggetScriptEnvironment- For context information
Return:
- A JSON error object with details about the last error
Example:
error.Set(errorCode; text; scriptStep)
Description: Creates a structured error object with the specified error code, message text, and script step information.
Parameters:
errorCode: The numeric code for the errortext: Custom error message (uses default error text if empty)scriptStep: The name of the script step where the error occurred
Dependencies:
error.Text- For default error messagesgetScriptEnvironment- For context information
Return:
- A JSON error object
Example:
error.SetFromDAPI(DAPIResponseObject; scriptStep)
Description: Creates an error object from a Data API response object, adding the script step where the error occurred.
Parameters:
DAPIResponseObject: The FileMaker Data API response objectscriptStep: The name of the script step where the error occurred
Return:
- A JSON error object with details from the Data API response
Example:
error.SetFromHttpResponse(response; scriptStep)
Description:
Creates an error object from an HTTP response. If the response is successful (ok is true), it returns a no-error object with code 0.
Parameters:
response: An HTTP response object containing at least an "ok" propertyscriptStep: The name of the script step where the error occurred
Dependencies:
error.Set- For creating the error object
Return:
- A JSON error object with details from the HTTP response, including HTTP status code and response body for errors
Example:
error.Text(errorCode)
Description: Looks up the description for a FileMaker error code. This function contains a comprehensive list of FileMaker error codes and their corresponding descriptions.
Parameters:
errorCode: A FileMaker error code (number)
Return:
- A string describing the error associated with the error code
Example:
Usage Tips
-
Consistent Error Handling: Use these functions to standardize error handling across your FileMaker solution.
-
Error Logging: Store error objects in a log table for troubleshooting.
-
Chaining: These functions can be chained together - for example, use
error.GetLast()to capture an error anderror.GetCode()to check the error code: -
Custom Errors: Create custom error objects with
error.Set()when you need to generate your own error conditions. -
Integration with Other Functions: These error functions are designed to work with the miscellaneous utility functions for complete error handling capabilities.