enhancement
major
minor
defect
critical
major
minor
major
#30124
OpenAPI Server: The error message for a failed script is unreadable and is generated outside the interaction context
Problem
If the script for an OpenAPI method (ServiceMethodByExpression) fails, the OpenApiServer writes a message to the log that is of little use for diagnostics:
INFO OpenApiServer - API request to '/equipments/{uuid}' failed: Evaluation of 'query(...)' failed, arguments: (),
variables: {computeTransformationMatrix=(planningElt -> {...}); createJSON=(equipment -> { ... several thousand characters of script ... }); uuid=5324fb1f-...; ...}:
Evaluation of '...' failed, arguments: (), variables: {computeTransformationMatrix=(planningElt -> {trafoMatrix = $planningElt.ERROR: java.lang.IllegalStateException: KnowledgeBase operations require a valid InteractionContext.; ...}:
Cannot load object data: Unable to fetch knowledge item with id 'ID(2916037)' of type 'epp.plan.Equipment': ...
The message has two issues:
- Parts of the message are corrupted. In the second part, instead of the objects, there are only errors of the type ERROR: java.lang.IllegalStateException: KnowledgeBase operations require a valid InteractionContext..
- The message is extremely long and contains the entire script—even twice. The message for the failed evaluation contains the complete variable context. This also includes the functions that the script binds via `let` (in the example: `createJSON`, `createJSONWithSecurity`, ` computeTransformationMatrix`), i.e., the entire script of the method. And the same message appears twice in the output (see Cause). The parameters used by the caller to invoke the method and what actually failed are lost in this output.
Cause
- ServiceMethodByExpression.handleRequest executes the script in TLContextManager.inPersonContext(...) or ThreadContext.inSystemContext(...). If it fails, `execute()` wraps the exception in `new ComputationFailure(ex.getMessage(), ex)`. Its message is therefore generated while still within the context.
- OpenApiServer.process catches the ComputationFailure only after this context has ended and constructs the message in messages(ex) from all the causes of the exception. In the process, the message of the wrapped exception is generated a second time, this time outside the context.
- This exception is a TopLogicException with the key ERROR_EVALUATION_FAILED__EXPR_ARGS_DEFS, which SearchExpression.evalWith populates with the expression, the arguments, and the EvalContext. I18NRuntimeException.getMessage() translates the key only when called, invoking toString() on the business objects in the process. Outside the context, these can no longer be loaded. Because the two versions of the message differ as a result, removing duplicate messages in ` messages(ex) ` does not work.
Solution
ServiceMethodByExpression constructs the message for a failed call itself (FailureMessages.scriptFailure) while still within the Interaction context. It contains:
- the caller’s parameters as they are passed to the script (binary data only with their size),
- the expression of the innermost failed evaluation with its function arguments, but without the context variables. Aside from the caller’s parameters, these consist primarily of the functions from the method’s script, which is already determined by the path.
- the messages indicating the causes of this evaluation, e.g. , “Unable to fetch knowledge item ...”
The method’s path remains at the beginning of the message from OpenApiServer. In the ComputationFailure branch, OpenApiServer now only takes the final message and no longer iterates through the causes.
The parameters are output in full, just as they were previously as part of the variable context. Sensitive parameters are not protected by this; that is not the subject of this ticket.
ERROR_EVALUATION_FAILED__EXPR_ARGS_DEFS in SearchExpression remains unchanged because other users (e.g., error dialogs in the user interface) may need the complete context.