Form model is broken but SME shows no errors

Hi there,
so I recently encountered this problem when fixing a form model after some changes in the underlying data model.

Problem
I had gone through the form model and fixed all errors shown in the SME but when trying to open my form model in the application I got a post processing error. I then went back to the SME and discovered that the preview of this form model wasn’t working either. It looked like this:
image
As you can see, no errors in the form model according to the SME but the preview says my form model is broken.

Solution
In our application the post processing error was just pointing to the form model without further information. One strategy that we considered was setting a breakpoint and debugging from there. What I actually did was perhaps a bit less sophisticated but probably a bit quicker (and easy enough for me to pull off without the support from a developer).
Because the preview in the SME can be refreshed very quickly without having to save your form model first, it’s actually quite time efficient to use it for trouble shooting here. As I had no idea what part of the form model was affected, I deleted complete screens from the form model one by one refreshing the preview after each. When the preview worked again, I knew that this screen had the affected control. Then I undid all my deletions by hitting cancel and focused on the affected screen. Using the same strategy on screens, control groups and then single controls, I could narrow it down to two expressions*. Turns out in two expressions some data fields were referenced that had been renamed in the data model. Because these data fields were used inside a “case” clause, they were not caught by the the validation mechanism of the SME.

*One caveat with this strategy is that you should always confirm that only a specific section of the form model is affected. It’s possible that there are two separate sections are affected and you might only identify the last one by this strategy. If multiple sections are affected, it becomes a lot more complex to narrow down the problem, so this is probably only feasible if there’s only one or two broken controls.

Bug
I could reproduce the bug with simple example models, however I could not reproduce the exact error message in the preview window. In my example case, I get a different error message. I believe this is the same bug regardless but my original form model is quite large, so I believe this has something to do with that.

So in my example models, I have three data field “First Name”, “Last Name” and “Order”. This allows you to enter a first and last name and then specify in which order they should be displayed:
image
In my example expression I have two “cases” depending on which order is selected:
image
When everything is working this should look like this:
image
I have intentionally broken the expression by renaming my data field “FirstName” to “FirstNameX” and not adjusting my expression. As you can see, the form model is shown to have no errors in the SME even though the expression is broken. Now in the preview, as soon as the expression is triggered by filling the “Order” field, you get an error like this:
image
You can trigger the same error immediately upon loading of the preview if you set “Order” via initial value or by adjusting the expression to trigger even if “Order” is unset like this:
image

Here are the example models:

Test_DM.json (2.9 KB)
Test_FM.json (2.8 KB)

Bug ticket was created: A12-17507

We were finally able to reproduce the original error message. :partying_face:

As Lea wrote, the issue is with case statements of expressions. All field references inside a case statement are not validated. Depending on the type of reference, a different error handling occurs as soon as the modeled expression case is met.

So far, we found 2 error handlings:

  1. the invalid field reference is part of the text output (see also the detailed description above)
    Example:
    kontext(Test_root){
    case[Order] != ""{
    [InvalidFieldRef] " any text" text output with invalid field reference
    }
    }
    Result: SME Form Model Preview crashes, throwing an Invalid path error.

  2. there is a nested case statement and the invalid field reference is part of the inner case clause
    Example:
    kontext(Test_root){
    case[ValidFieldRef] != ""{ outer case with valid field reference
    case[InvalidFieldRef] = "FirstNameFirst" inner case with invalid field reference
    {"Any text"}
    }
    }
    Result: SME Form Model Preview displays “The preview couldn’t be rendered correctly due to issues in the form model. Please fix them first.” error without crashing.

The second case is the original issue that Lea encountered and which was harder to reproduce.

All information was added to the previous mentioned bug ticket A12-17507.

Update: This issue has been fixed in 2025.06-ext1.