IMD SolutionComputing LibraryShop main store

Troubleshooting

Why a Node-RED Sparkplug B flow throws a touppercase type error

Edge computing and IIoT Published 7 min read By IMD Solution engineering team

Short answer

A touppercase type error in a Sparkplug B publishing flow means a function block received a number, a float or an integer, where toUpperCase() needs a string. The nested PropertySet payload format is not the fault. Locate the function node that calls the method, convert that value or drop the conversion, then republish and check the payload separately.

On this page
  1. Why does a Node-RED Sparkplug B flow throw a touppercase type error?
  2. How do I find the function node that actually threw the error?
  3. What exactly goes wrong inside the function block?
  4. How should the function block be changed?
  5. Should numeric Sparkplug B metrics be turned into strings?
  6. Is the nested PropertySet payload format the problem?
  7. Which other Node-RED errors follow the same rule?
  8. How do I verify the flow after the fix?
  9. Questions asked

Your Node-RED flow was building a Sparkplug B payload with nested properties, and the debug tab answered with a touppercase type error instead of a published message. The fault is not the nested PropertySet format: the error means some function node in the flow called the string method toUpperCase() on a number, and numbers have no such method. Find the node named in the debug tab, convert values that are genuinely text, leave numeric metrics numeric, deploy, and only then judge the payload format on a clean republish. This article walks the diagnosis, the fix inside the function block, and the verification on the receiving side.

Why does a Node-RED Sparkplug B flow throw a touppercase type error? #

The touppercase type error means a function block in your flow called the string method toUpperCase() on a value that is a number — a float or an integer — and JavaScript throws a TypeError because that method exists only on strings.

The debug tab prints the name in lowercase; in your code the method is spelled toUpperCase(), the way JavaScript defines it. The error is plain JavaScript inside the flow: it fires before any message reaches your Sparkplug B encoder or the broker, so neither the MQTT connection nor the encoder node nor the payload format is implicated at this point. A flow that builds nested properties tends to pull in extra fields — equipment codes, asset tags, station identifiers arriving from an inject node or an API call — and one of those fields is reaching the method with a numeric type. Correct that one value at the function block; do not redesign the payload to chase it.

How do I find the function node that actually threw the error? #

The debug tab names the node that raised the error, so open that node and read its code — in the reported failure, the throwing node was not the payload builder whose code was on screen.

That mismatch is the whole trap: one function block was under review while a different one threw. Two quick ways to pin the location down. Export the flow from the editor menu and search the exported JSON for the method name; every function node carrying a toUpperCase() call shows up in the export. Or open the function node the debug tab points at and check the runtime log, where the stack trace includes the line number inside that node. Node-RED executes every node in the flow, so an error anywhere in it surfaces in the debug tab, no matter which node's code you had open.

What exactly goes wrong inside the function block? #

Inside the function node, one input reaches toUpperCase() with a JavaScript type of number, and numbers have no such method, so the call throws before any payload object exists — the worked example below shows the mechanics line by line.

Take a function block that assembles an identifier from three injected fields: line and station arrive as numbers, and code arrives as a short text string.

// msg.payload arrives as { line: 4, station: 7, code: "ah1" }
let tag = msg.payload.line + "-" + msg.payload.station;
// evaluated left to right: 4 + "-" gives "4-", then "4-" + 7 gives "4-7"
msg.topic = tag.toUpperCase();
// tag is the string "4-7"; digits have no letter case, so the result stays "4-7"
msg.payload.code = msg.payload.code.toUpperCase();
// "ah1" is a string, so this returns "AH1" and the line is legal
let alias = msg.payload.station.toUpperCase();
// station is the number 7 and numbers carry no toUpperCase method, so this throws:
// TypeError: msg.payload.station.toUpperCase is not a function

The arithmetic in the first two lines is the part engineers miss: once a string operand appears, the plus operator concatenates instead of adding, so 4 and 7 never produce 11 — they become the text 4-7. Three of the four lines are legal. The single numeric field handed straight to toUpperCase() kills the node, and the debug tab blames this function block even though most of its code was fine.

How should the function block be changed? #

Convert a value only when it is genuinely text, and leave every numeric metric alone: wrap the value in String() once at the line that needs text, and delete or bypass the uppercase call on numbers, because digits have no letter case and uppercasing them changes nothing.

  1. Open the function node the debug tab named.
  2. Find every toUpperCase() call in that node.
  3. For each call, decide what the value is: an identifier you format for display, or a number the payload must keep numeric.
  4. If it is genuinely text that sometimes arrives as a number — an API returning the bare number instead of the quoted form is common — wrap it once at that line, String(msg.payload.station) for the example above, and the uppercase call then works.
  5. If the value must stay numeric in the Sparkplug B payload, delete the uppercase call or branch around it; for a display tag, build the string by concatenation as the worked example does and uppercase that string instead.
  6. Click Deploy, trigger the flow once, and confirm the debug tab shows values instead of a TypeError.

The decision, case by case: a text field formatted for display gets one explicit String() conversion at the line of use; a numeric metric gets the uppercase call deleted, since the call never changed its value anyway. Nothing else in the flow needs to move, and no payload structure needs to change to clear this error.

Should numeric Sparkplug B metrics be turned into strings? #

No — a Sparkplug B metric carries a declared datatype alongside its name, so publishing a numeric value as text turns a number the plant expects into a string, and consumers that build analog values from it reject the point.

The payload format is structured by design: each metric is described with fields such as its name and its datatype, and the datatype tells the consumer whether a value is analog, digital or text. Publishing the number 72.5 as the text 72.5 silences the JavaScript error and creates a worse fault downstream, because the consumer's analog point then receives a string where it needs a number — the same failure described in why a quoted MQTT JSON value fails an analog point. Keep each metric's declared type and fix the function block instead.

Is the nested PropertySet payload format the problem? #

Not on this evidence — the type error is thrown by JavaScript inside a function node before any payload is serialized, so the nested PropertySet structure has not even been tested when this error appears.

Clear the type error first: any conclusion about the PropertySet format drawn while the error is still firing is unsupported, because no message has left the flow. Republish once the function block is fixed, and judge the payload from the encoder's or the consumer's own response. If points then arrive blank at the SCADA side on nested structures, that is a separate diagnosis with its own cause, covered in SCADA MQTT points blank with nested JSON payloads.

Which other Node-RED errors follow the same rule? #

Any message of the form value.method is not a function means the method does not exist on that value's type, so the same diagnosis covers toLowerCase receiving a number or toFixed receiving a string — and the throwing name is rarely the code you were editing.

Two documented cases show the pattern. A third-party node that expects the text values toggle, on or off threw TypeError: msg.payload.toLowerCase is not a function when a non-string reached it — the identical mismatch around a mirrored method. And Node-RED's issue tracker records a stock change node reporting RED.utils.validateTypedProperty is not a function, caused by a stale cache rather than by anything the user typed. The working rule: an is-not-a-function error names the node where the fix belongs, even when it is a node you never opened; if the named node is one you have never edited, redeploy and reload the editor before rewriting anything.

How do I verify the flow after the fix? #

Deploy the changed function node, trigger the flow once, and confirm the debug tab shows the metric values instead of the type error, then check the receiving side for one known tag, value and timestamp before calling the fault closed.

Deploy is what makes the edit live; an undeployed fix explains an error that refuses to go away. On the receiving side, confirm one known metric arrives with its expected value at its expected timestamp, because a flow that no longer errors but also no longer publishes is a silent data gap for anyone acting on that number. If a new error appears from the encoder or the consumer after the clean republish, treat it as its own fault — for example, resolving a Sparkplug B DDATA INVALID_ARGUMENT timestamp fault is a separate procedure with its own cause and fix.

Questions asked

How do I check a value's type before calling toUpperCase()?

Put the type itself into the message for one test run: add a temporary line that sets the payload to typeof msg.payload.station, deploy, trigger once, and read the debug tab. typeof reports number for a numeric value and string for text. Delete the temporary line before the fix goes into service.

Why did the flow only start throwing after the nested properties were added?

The uppercase call was probably always present, but the data reaching it changed. Building nested properties usually means injecting extra fields, identifiers pulled from an API or an inject node, and a field that arrives as the number 7 instead of the text 7 breaks a call that previously only ever saw text. That is why the new payload shape and the old string operation collide on the first run.

Can a catch node clear the touppercase error for me?

No. A catch node reports the error and the node that raised it, which makes it useful for locating the fault in a large flow, but it reroutes or logs the error rather than repairing it. The type mismatch itself is only fixed in the function block, by converting the value or removing the uppercase call.

Does this error stop anything from reaching the MQTT broker?

Yes, for that message. The TypeError is thrown while the function block runs, so the flow never builds the payload and never publishes it; the broker simply receives nothing on that path. Messages that were published before the fault remain on the broker unchanged, which is why the receiving side can look half-alive while the flow is broken.

Keep reading

  • Troubleshooting

    Fix Node-RED InfluxDB write errors after a network outage

    When InfluxDB output nodes throw ECONNRESET after a network outage, Node-RED is usually still holding dead TCP client sessions. Confirm the database is reachable from the Node-RED host, then use the Deploy menu's flow-restart option to rebuild every connection while the runtime stays up.

    Edge computing and IIoT

  • Troubleshooting

    Why a Sparkplug edge node stays stuck in a rebirth loop

    A rebirth loop that never converges means the publisher answers every rebirth correctly and something else then contradicts that birth. With one 0-255 sequence counter per edge node ID, either a second client publishing into the same Group/Edge Node or a bare-name DDATA the birth never defined makes the subscriber reject every cycle. Isolate it with a broker client list and a wildcard capture before touching the publisher.

    Edge computing and IIoT

  • Troubleshooting

    Why MQTT Engine shows online status after an edge node drops

    An Info/Online tag that stays true with Good quality is not proof the edge node is alive: Engine's online state comes from the node's Sparkplug death certificate, and earlier Engine versions marked tags stale only on Engine shutdown. Read Info/Online, tag quality and Store & Forward stored metrics as three separate indicators, retest on Engine 4.0.8 with Ignition 8.0.16 or later, and compare against a node that reports correctly before escalating.

    Edge computing and IIoT

Why AFElementSearch throws error BC30182 type expected