Set LastError [ Number ] Script Step (for returning script errors)

Idea created by mrwatson-gbs on Apr 3, 2016
    • Hemant Kumar Patel
    • chivalry
    • psc
    • arnoldkegebein
    • mrwatson-gbs
    • Markus Schneider
    • richardsrussell



    There is currently no way of passing an error number back to a calling script, other than to encode it in the script result - often along with other result information - which can make script result + error processing unnecessarily complex.


    It has been suggested elsewhere, that having an extra channel for passing error numbers back to the calling script could simplify the processing of script errors and script results.


    Given that FileMaker already has a 'channel' for dealing with errors - the Get( LastError ) function - my suggestion is to leverage this existing functionality.




    1. A new Script Step

      Set LastError [error number]

      to make it possible set the value returned by the Get ( LastError ) function.
    2. A custom/private error range to be set aside for developers to use for their own internal errors.
      • One possible range would be negative numbers < -1 (-1 is the FM error "unknown error")


    Some examples:


        # Simulate an empty result set

        Set LastError [ 401 ]

        Exit Scrip t ["No results" ]




        # Find something...

        Enter Find Mode [ ]

        Set Field [ MyTable::MyField ; $Search ]

        Perform Find [ ]

        If [ Get( LastError ) = 401]

        # ...but ignore error 401

            Set LastError [ 0 ]

        End If

        If [ Get( LastError )]

            #Handle real error in search criteria...

        End If



        # DON'T Pass missing record error back to calling script



           Go to Record [ Next ; Exit after Last]

        End Loop

        Set LastError [ 0 ]

        Exit Script [ ]




        # Pass a custom error back to the calling script, inc. custom error message in the script result

        Set Last Error [ -100 ]

        Exit Script ["Function not yet implemented" ]



        # Passing errors back as real errors after rollback

        Perform Script [ "MySubscript" ]

        -> Script "MySubscript"

            # Do something...

            # long

            # and complicated

            # and error-prone

            # ...

            Set Variable [ $error ; Get( LastError ) ]

            If [ $error ]

               # Code to roll back / tidy up

            End If

            # Now pass back the earlier error AS A REAL ERROR, instead of as a pseudo-error embedded in the ScriptResult

            Set LastError [ $error ]

            Exit Script [ $ScripResult  ]


        If [ Get( LastError ) ]

            # Handle real errors here


            # Handle Script Result here

        End If





    • Return errors as REAL errors, instead of pseudo-errors in the script result
      • Scripts can clean up after an error occurs, yet still pass a real error back.
    • Improved Script Result
      • ScriptResult and error result can be handled separately
      • ScriptResult is freed up for passing the result of the script function
      • Simplified script result handling
      • Simplified and standardised error handling via Get( LastError )
    • Subdue unwanted LastErrors (notoriously errors 401 and 101)
    • Leverages existing functionality
      • Minimises added complexity to FileMaker
      • More FileMakery
    • Solution dependent errors can be integrated into Get( LastError ) + custom error number space
      • No need to build own error handling system
      • Greater productivity


    Use Cases


    • Return error from script - See examples above
    • Return error from server-side script
    • Subdue undesired errors - See examples above
    • Construct + use your own custom errors natively


    This idea helps Make FileMaker more modular by providing a cleaner script-calling-API.