format_validation_error

Function format_validation_error 

Source
pub fn format_validation_error(
    code: &str,
    file_path: &str,
    error_kind: &str,
    line_num: usize,
    col_num: usize,
    message: &str,
    help: &str,
    underline_length: usize,
) -> String
Expand description

Format a validation error with beautiful Rust/Gleam-style output

This function creates consistent error messages across all Tana systems:

  • tana-runtime (native Rust)
  • tana-edge (native Rust)
  • playground (WASM in browser)
  • CLI tools (WASM in Bun/Node)

§Arguments

  • code - The source code containing the error
  • file_path - Path to the file (e.g., “contract.ts”)
  • error_kind - Category of error (e.g., “Invalid Import”, “Type Error”)
  • line_num - Line number (1-indexed)
  • col_num - Column number (1-indexed)
  • message - Error message
  • help - Help text explaining how to fix
  • underline_length - Number of characters to underline (for ^^^)

§Example

use tana_validation::format_validation_error;

let error = format_validation_error(
    "import { console } from 'tana/invalid';",
    "contract.ts",
    "Invalid Import",
    1,
    26,
    "Module 'tana/invalid' not found",
    "Available modules: tana/core, tana/kv, tana/block",
    12
);

// Produces:
// Validation Error
// ❌ Invalid Import
//
// ┌─ contract.ts:1:26
// │
//   1 │ import { console } from 'tana/invalid';
//     │                          ^^^^^^^^^^^^ Module 'tana/invalid' not found
// │
// = help: Available modules: tana/core, tana/kv, tana/block
// │
// └─