Active Code Updates

Posted on by Chris Warburton

I’ve updated my active code setup to fix a problem which has caused me much chagrin: handling of stderr.

Active Code Overview

“Active code” means:

  1. Writing a document in a markup format (HTML, LaTeX, Markdown, etc.) which contains snippets of code
  2. Having that code automatically executed during the document rendering process
  3. Having the results of that execution affect the document which is produced

For example, we might be writing a document which compares the execution time of different algorithms. There are two problems we might encounter, which active code can help us avoid:

My Setup

I solve the three requirements of active code using three interacting programs:

The Problem

Until now, PanPipe has avoided handling the standard error stream of our shell commands. If the command triggers an error (exits with a non-zero status) then the rendering is aborted, but we can’t see why.

I’ve been working around this by redirecting stderr to stdout and overriding exit codes, so that error messages appear inside the resulting document. Not only is this dangerous (there is no indication that the rendering failed unless we read through the document looking for error messages, if there are any), but it’s also incredibly inconvenient.

Finally, I’ve fixed the problem at the source: PanPipe now echoes stderr from shell commands to its own stderr, whether or not it succeeds or fails. This makes it much easier to debug the active code embedded in our documents.