`Message` with severity `'Error'` does not stop evaluation

Abierto
#415 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
54/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript
Área
backend, testing

Línea de trabajo

Start with src/elm/message.ts and the TestMessageError case in tests/cql/CqlErrorsAndMessagingOperatorsTest.xml; compare the current listener behavior with the specification quoted in the issue. Check both true and false conditions, Error and Warning severities, and a Message value used by a later expression. Done means the error case fails evaluation as expected while the other cases continue to return their source values.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

When the condition of Message is true and the severity is 'Error', the specification says evaluation stops with a run-time error. cql-execution calls the message listener (if any) and returns the source value instead, so evaluation continues (src/elm/message.ts).

Reproduction
library MessageSemantics version '1.0.0'

define ErrorTrue: Message(1, true, 'c', 'Error', 'boom')
define ErrorUsedLater: Message(1, true, 'c', 'Error', 'boom') + 1
define WarningTrue: Message(1, true, 'c', 'Warning', 'w')
define ErrorFalse: Message(1, false, 'c', 'Error', 'boom')
Expression Expected cql-execution 3.3.2 cql-execution 4.0.0-beta.1
ErrorTrue run-time error 1 1
ErrorUsedLater run-time error 2 2
WarningTrue 1 1 1
ErrorFalse 1 1 1

The JavaScript build of the reference engine (@cqframework/cql 5.8.0) raises an error for the first two expressions.

Specification

CQL Reference, Message: "Error – The operation produces a run-time error and return the message to the calling environment. This is the only severity that stops evaluation. All other severities continue evaluation of the expression."

The official test TestMessageError in cql-tests (tests/cql/CqlErrorsAndMessagingOperatorsTest.xml, invalid="true") expects this error; cql-execution fails it.

Effect on published libraries

Several published libraries end a case with Message(<placeholder>, true, ..., 'Error', ...) for inputs they cannot handle, relying on evaluation to stop. With cql-execution the placeholder is returned and evaluation continues. Two examples (FHIR R4 data through cql-exec-fhir 2.2.0, cql-execution 3.3.2 and 4.0.0-beta.1 give the same results):

  • WHO SMART HIV (smart.who.int.hiv), HIVCommon.GetDurationInDays(value FHIR.Duration): the else branch is Message(1000, true, 'Undefined', 'Error', 'Unsupported duration unit ' + value.code.value). For a MedicationRequest authored on 2026-01-10 whose dispenseRequest.expectedSupplyDuration is { "value": 30, "unit": "days" } (no code) or has "code": "day", the function returns 1000 and HIVCommon."Prescription Relevant Period" evaluates to Interval[@2026-01-10, @2028-10-06] instead of raising an error (with "code": "d" it is Interval[@2026-01-10, @2026-02-09]).
  • CDC Opioid CDS (fhir.cdc.opioid-cds-r4), OpioidCDSCommon.GetDurationInDays: same pattern. The placeholder becomes 1000 '1', so OpioidCDSRoutines."Is Acute Pain Prescription?" and "Is Subacute or Chronic Pain Using Expected Supply Duration" both evaluate to null for such a prescription.

Guards of the form Message(null as T, true, ..., 'Error', ...) (for example for a string alternative of a choice-typed element) likewise return null, and the calling logic continues as if the input were merely missing.

Documented behaviour and a workaround

OVERVIEW.md (MessageListener) says that ConsoleMessageListener logs Error messages to stderr, so continuing may be intended. A listener that throws from onMessage when severity === 'Error' gives the specified behaviour: with 3.3.2 and 4.0.0-beta.1, ErrorTrue and ErrorUsedLater then raise an error and WarningTrue/ErrorFalse still return 1. If continuing is the intended default, documenting that 'Error' does not halt evaluation, and how to opt in to halting, would help library authors and integrators.

Suggested fix

After notifying the listener, throw an error carrying the code and message when the condition is true and the severity is 'Error'. The specification does not say whether the severity comparison is case-sensitive; the reference engine treats 'error' as 'Error'.

Environment

The same code is on master at e87e3fa (src/elm/message.ts).

cql-execution 3.3.2 and 4.0.0-beta.1, Node 24, Windows 11, TZ=UTC, translator @cqframework/cql 5.8.0.

Lenguaje dominante
JavaScript
Estrellas
86
Forks
40
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cqframework/cql-execution

Todos los issues de cqframework/cql-execution

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.