Module

tuck/error

src/tuck/error.pooka

When 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

src/tuck/error.pooka:16
class Pos(line: Int, column: Int)

A place in a template: lines and columns both count from one.

field

line

src/tuck/error.pooka:16
line: Int
INFERREDInt
field

column

src/tuck/error.pooka:16
column: Int
INFERREDInt
constructor

new

src/tuck/error.pooka:16
INFERREDfn(Int, Int) -> tuck/error.Pos
class

TuckError

src/tuck/error.pooka:20
class TuckError(template: String, at: Pos, message: String)

Something wrong with a template, or with rendering it: which template, where in it, and what.

field

template

src/tuck/error.pooka:20
template: String
INFERREDString
field

at

src/tuck/error.pooka:20
at: Pos
field

message

src/tuck/error.pooka:20
message: String
INFERREDString
constructor

new

src/tuck/error.pooka:20
INFERREDfn(String, tuck/error.Pos, String) -> tuck/error.TuckError
function

describe

src/tuck/error.pooka:30
describe(problem: TuckError) -> String
INFERREDfn(tuck/error.TuckError) -> String

The problem as one line, ready to print.

Pooka
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"
function

suggest

src/tuck/error.pooka:46
suggest(wanted: String, known: List(String)) -> String
INFERREDfn(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.

Pooka
import tuck/error

assert error.suggest("uppr", ["upper", "lower"]) == "; did you mean `upper`?"
assert error.suggest("zzz", ["upper"]) == ""
function

distance

src/tuck/error.pooka:82
distance(from: String, to: String) -> Int
INFERREDfn(String, String) -> Int

How 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.

Pooka
import tuck/error

assert error.distance("kitten", "sitting") == 3
assert error.distance("fro", "for") == 1