Write fails after process in the same code block
-
What you'll see
A
.hashpage or display template that renders an example withprocess()answers with an error page instead of the content:Error: 'write' method call failed with error 'Object reference not set to an instance of an object.'The reported line is a
write()call that comes after theprocess()call in the same#{ }#block. The samewrite()worked beforeprocess()was added, and everywrite()earlier on the page still works. -
What's actually happening
Observed on this site on 2026-10-29, in the display template for the function reference. One code block ran each example through
process()and then wrote the tabs that show it:#{ let out = ""; try { out = process(Code, data); } catch (e) { out = ""; } write('<h2>Example</h2>'); // fails: 'write' method call failed }#Every function page answered with the error. What still worked on the same page:
write()calls in code blocks before the one that calledprocess().write()in a later, separate code block — here an included template at the end of the article.- A
#expression#after the block, emitting a variable the block had built.
So the failure is tied to calling
write()in the same block afterprocess()has returned. The old version of the template never hit it, because it emitted the example output with expressions in the markup rather than withwrite(). -
What to do
Build the markup as a string and emit it with an expression after the block. Declare the variable at the top level of the block so the expression can see it:
#{ let out = ""; try { out = process(Code, data); } catch (e) { out = ""; } let html = '<h2>Example</h2><pre><code>' + docly.htmlEncode(out) + '</code></pre>'; }# #html#Alternatively, close the block after
process()and do the remainingwrite()calls in a new#{ }#block.- Encode what you emit — an expression outputs the string verbatim (see Hash expressions do not escape HTML).
- A page that calls
process()is easy to break this way and the error takes the whole page down, so check it with a cache-busted request after every change, and readdocly consolefor the error and its line.
Last reviewed 29 Oct 2026