Module
tuck/error
src/tuck/error.pookaWhen a template goes wrong, say where, and say it kindly.
Every problem Tuck reports, while reading a template or while rendering
one, is a TuckError: the template's name, the line and column, and a
sentence about what went wrong. Misspelled names come with a suggestion.
API reference
class Pos(line: Int, column: Int)
A place in a template: lines and columns both count from one.
line: Int
Intcolumn: Int
Int
fn(Int, Int) -> tuck/error.Posclass TuckError(template: String, at: Pos, message: String)
Something wrong with a template, or with rendering it: which template, where in it, and what.
template: String
Stringat: Pos
tuck/error.Posmessage: String
String
fn(String, tuck/error.Pos, String) -> tuck/error.TuckErrordescribe(problem: TuckError) -> String
fn(tuck/error.TuckError) -> StringThe problem as one line, ready to print.
import tuck/error.{Pos, TuckError}
let problem = TuckError("page.tuck", Pos(3, 7), "something is wrong")
assert error.describe(problem) == "page.tuck:3:7: something is wrong"
suggest(wanted: String, known: List(String)) -> String
fn(String, List(String)) -> String; did you mean x? when one of the known names is close to wanted,
or nothing at all. Close means a few edits away: one for very short
names, two or more for longer ones.
import tuck/error
assert error.suggest("uppr", ["upper", "lower"]) == "; did you mean `upper`?"
assert error.suggest("zzz", ["upper"]) == ""
distance(from: String, to: String) -> Int
fn(String, String) -> IntHow many edits turn one text into the other, where an edit adds,
removes or changes one character, or swaps two neighbours: fro is one
edit from for.
import tuck/error
assert error.distance("kitten", "sitting") == 3
assert error.distance("fro", "for") == 1