« Add page links for Fi… | Home | Four month Russian wa… »

New error log functions for FileMaker

For last version, we got the functions ClearErrors and HadErrors to track whether a script had errors. You can think here like a try catch, where you can run a script later check in the script whether something failed and log that failure. At the MBS FileMaker Plugin workshop this week, we got a few new ideas to catch errors better. We got the idea to collect error logs and provide them as JSON to the developer.

 

Let us show you a test script:

 

# start error logging

Set Variable [ $r ; Value: MBS("ClearErrors") ] 

# cause some errors

Set Variable [ $r ; Value: MBS("test"; 1; "Hello") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.Print"; 1; "Hello") ] 

# now query error log

Set Variable [ $r ; Value: MBS("ErrorLog") ] 

Set Field [ Kontakte::Nachname ; $r ] 

Show Custom Dialog [ "Error Log" ; $r ] 

 

As you see we call ClearErrors function early to clear the list (if needed). Then we cause two MBS errors here and don't check result right away. 

On the end of the script, we query ErrorLog function and get a JSON back with the error details:

 

[

{

"function": "test",

"result": "[MBS] Unknown function: test",

"parameter": ["test", 1, "Hello"],

"fileName": "Kontakte",

"scriptName": "test Errors",

"currentTimeStamp": "23.06.2022 09:28:34"

}, 

{

"function": "DynaPDF.Print",

"result": "[MBS] DynaPDF.Print is only supported for Windows. Please use PDFKit.Print on Mac.",

"parameter": [

"DynaPDF.Print", 

1, 

"Hello"

],

"fileName": "Kontakte",

"scriptName": "test Errors",

"currentTimeStamp": "23.06.2022 09:28:34"

}

]

 

As you see we provide a JSON with parameters, result, function name and for the context the timestamp, script and file name. We could add more in future there.

 

If you like to do a try/catch in FileMaker similar to other programming languages, you can use a Loop construct. The loop always runs once, but allows you to exit it early in case of an error. You can check error state with Get(LastError) for FileMaker functions and MBS("IsError") for our plugin functions. The script may look like this:

 

Set Error Capture [ On ]

# start error logging

Set Variable [ $r ; Value: MBS("ClearErrors") ] 

Loop

# cause some errors

Set Variable [ $r ; Value: MBS("test"; 1; "Hello") ] 

Exit Loop If [ MBS("IsError") ] 

Set Variable [ $r ; Value: MBS("DynaPDF.Print"; 1; "Hello") ] 

Exit Loop If [ MBS("IsError") ] 

# FileMaker error -> missing script

Perform Script [ Specified: From list ; <unknown> ; Parameter:    ]

Exit Loop If [ CheckError ] 

# here we are done and no error happend

Exit Script [ Text Result: "Success" ] 

End Loop

# now query error log

Set Variable [ $r ; Value: MBS("ErrorLog") ] 

# and notice developer

Show Custom Dialog [ "Error Log" ; $r ] 

 

MBS FileMaker Plugin automatically adds an error log entry for the errors in our plugin. To catch FileMaker errors, we got a custom function to add the FileMaker own errors to the error log:

 

Let([

e = Get(LastError);

d = Get(LastExternalErrorDetail);

r = MBS("AddToErrorLog"

JSONSetElement ( "{}"

   [ "lastError" ; e; JSONNumber ]

   [ "lastErrorMessage" ; d; JSONString ]

   [ "scriptName" ; Get(ScriptName); JSONString ];

   [ "fileName" ; Get(FileName); JSONString ];

   [ "currentTimeStamp" ; Get(CurrentTimestamp); JSONString ]

))

]; e  0)

 

 

What do you think about this? This is early and please let us know suggestions, so you can try to use it later this summer and fall for your solutions.

 

Let us know if you have ideas for improvements.

Claris FileMaker Plugin
23 06 22 - 12:10