liveBook · Manning

Issue message

As explained in Building User-Friendly DSLs

A textual description of a constraint violation and, ideally, the way to correct it.

An issue message is a string describing a constraint violation. A constraints checker collects these messages for an AST object so invalid domain data can be identified and corrected near its context. section 9.2.2

Implement issue messages by:

  • Checking each constraint with an explicit negated condition and pushing a corrective violation message when the condition fails. section 9.2.2
  • Returning all messages from an issuesFor function instead of stopping at the first violation. section 9.2.2
  • Computing issues in the frontend projection so the information remains close to the affected object and updates reactively. section 9.2.2

Invalid data attribute

When a Data Attribute has an empty or non-string name, the checker adds “An attribute must have a name.” The interface displays a warning marker and exposes the message through the attribute’s tooltip. section 9.2.2

Listing 9.1 The initial implementation of the constraints checker
const isNonEmptyString = (value) =>      #1
     typeof value === "string" && value.trim().length > 0

const issuesFor = (astObject) => {   #2
    const issues = []                 #3
    const { settings } = astObject                 #4

    switch (astObject.concept) {         #5
        case "Data Attribute": {
            if (!isNonEmptyString(settings["name"])) {   #6
                issues.push(                            #7
                     "An attribute must have a name")
            }
            break   #8
        }
        // ...cases for other concepts to be added...           #9
    }

    return issues
}
module.exports.issuesFor = issuesFor

This listing shows the initial constraints checker: it validates a Data Attribute, accumulates its issue message, and returns the complete issue array. section 9.2.2

How Building User-Friendly DSLs covers it

How deep it goes
Explains collection, frontend placement, and tooltip display, while stopping short of a broader message model.
Examples
Uses an empty Data Attribute name, a warning marker, a tooltip, and the message “An attribute must have a name.”
What you can do after
Build it from scratch as a JavaScript checker that returns constraint violations and connects them to reactive UI feedback.
How it connects
Connects issue messages with constraints, abstract syntax trees, frontend projections, and tooltips.

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.