Skip to content

SpecificationX · Errors and diagnostics

10.1

Anatomy of a diagnostic

A diagnostic is not a sentence: it is a piece of data with a stable code, a class, a severity and a position. The message you read is built afterwards, in your language.

Markdown version

10.1.1 How it works

Every diagnostic has these parts:

PartWhat it is
codea stable name, the same in every language
classlexical, syntactic, semantic or runtime
severityerror, warning or information
spanwhere it starts and ends in the text
relatedother spans that help understand it
argumentsthe concrete data: a name, a type, a number
Figure 10.1-1.The same diagnostic seen as data and as a message. The message is built with a template in the interface language and the arguments.

At the top, the diagnostic as data: code incompatibleTypesInAssignment, semantic class and error severity, span on line 2 and arguments expected Integer and found String. An arrow with the language template leads to the presented message.

ProgramA diagnostic with arguments

Algorithm Mezcla
  Define total As Integer <- "diez";
  Write total;
EndAlgorithm

Diagnostics

  • incompatibleTypesInAssignment · error · 2:3 · Incompatible types in assignment: cannot assign string to integer

The program finishes with an error.

The data carries no text. To show it, the interface looks up the code's template in its language and fills in the arguments. That is why the message prose can be in English while the program uses the Spanish profile: user names are never translated, and the language's words appear in the active profile.

Appendix C lists every code with its class, severity and message.

In short

  • A diagnostic is data: code, class, severity, span and arguments.
  • The message is built afterwards, with the language's template.
  • The code does not change with the language.