martian-computing

CS 498MC Martian Computing at the University of Illinois at Urbana–Champaign

View the Project on GitHub davis68/martian-computing

Debugging Hoon

Learning Objectives

An Ontology of Error

We distinguish different aspects of programming flaws based on their observational mode:

We casually refer to all of these as bugs.

An exception is a manifestation of unexpected behavior which can give rise to a failure, but some languages—notably Python—use exceptions in normal processing as well.

Error Sources

Let’s enumerate the errors we know about at this point:

We know what Ford is: it’s the build vane. ++ride is the end-to-end Hoon compiler, which Ford is of course using to build the abstract syntax tree (AST). Two %ride failed errors are common: "%ride failed to compute type" and "%ride failed to execute". %slim failed means (one kind of) type issues, typically due to %ride failure. nest-fail indicates a failure to match the expected call signature of a gate.

The mint errors arise from typechecking errors:

For instance, conversion without casting via auras fails because

^-(tape ~[78 97 114 110 105 97])

A fish-loop arise when using a recursive mold definition like list. Alas, this fails today:

?=((list @) ~[1 2 3 4])

generator-build-fail most commonly results from composing code with mismatched runes (and thus the wrong children including hanging expected-but-empty slots).

mull-grow means it’s compiling the callsite of a wet gate (a generic gate; we’ll see these later).

If you really crash things hard—like crash the executable itself—then it’s a bail, which has the following modes:

Finally, although hinting at darker powers not yet unleashed, you can start a debugging console with |start %dbug and access it at your ship’s URL followed by ~debug (e.g., http://localhost:8080/~debug).

Debugging Strategies

What are some strategies for debugging?

Assuming that you are working within Urbit (i.e. in or on Arvo, not in the underlying host OS), you don’t have a debugger or a profiler available*. In that case, you have the slight help of the error message (a condition indicated as promoting “moral fiber”) and some standard debugging strategies:

If you run the Urbit executable with -L, you cut off external networking. This is helpful if you want to mess with a copy of your actual ship without producing remote effects. That is, if other parts of Ames don’t know what you’re doing, then you can delete that copy (COPY!) of your pier and continue with the original. This is an alternative to using fakezods which is occasionally helpful in debugging userspace apps in Gall.

The trouble with %sandbox code is that only %home desk code gets built by ++ford as executable. That may change someday, but it’s why we prefer fakezods instead of development desks today.

* I have found a reference to profiling support in the docs. ~$ sigbuc also plays a role as a profiling hit counter but I’ve not seen it used in practice as it would be stripped out of kernel code before being released.

Quality Hoon

Tlon suggests grading code according to certain stylistic and functional criteria:

But don’t produce A code on the first pass! Let the code mature for a while at C or B before you refine it into final form.