try
JS code reports errors by throwing them, Node's readFileSync and JSON.parse among them. try expr turns what the expression throws into an error, the second value, as Rook code returns errors: const text, err = try readFileSync(path, "utf8"). It catches everything thrown in the expression after it, and with await in it a rejected Promise too: try await fetch(url).
An expression that gives nothing, such as try writeFileSync(path, text), gives the error alone; a call of (User, error) gives the same (User, error), so one check covers both ways to fail. A try whose error is not kept is a compile error.
Loading or saving the task board can fail because storage or the network is unavailable. Use try at those boundaries to turn a thrown error or rejected request into the error value the app can report or handle.
// try turns what JS code throws into an error, the second value, as Rook returns errors for text in ["8080", "{", "[80, 443]"] { const port, err = try JSON.parse(text) if err != null { console.log("not JSON:", text) continue } console.log("parsed:", port) } async func connect(host string) string { throw error(`${host} does not answer`) } // With await, a rejected Promise becomes the error too const socket, err = try await connect("db.local") console.log(socket, err?.message)