Part III · Performance, Cross-Compilation, Security Governance & Diagnostics
Chapter 14
Compiler Diagnostics, Ownership Loans & Troubleshooting Reference
Resolving tight/spaced lexer rules, disjoint mut field loans, --strict-types narrowing, .secret firewalls, and stack traces
This guide explains Veko's compile-time and runtime diagnostics so you can resolve syntax, whitespace, ownership, strict-typing, .secret, and capability errors immediately.
1. Lexer & Whitespace-Sensitivity Diagnostics
Because Veko uses unshifted kebab-case words without call parentheses, whitespace around -, /, ., and [ carries exact syntactic meaning (veko inspect --tokens file.vk displays [tight] vs [spaced] on every token):
| Symptom / Error Message | Cause | Idiomatic Fix |
|---|---|---|
unknown word 'n-1' | Unspaced - inside identifier characters lexes as a single kebab-case word n-1. | Add spaces around binary subtraction: n - 1. |
unknown path 'a/b' | Unspaced / between words lexes as a module/refinement path a/b. | Add spaces around division: a / b. |
unexpected call / arity mismatch on len(xs) | Putting (...) immediately after a function name groups (xs) as arg 1, or fails arity. | Put parens around the call: (len xs). |
unexpected field / index on user .name or xs [0] | Space before . turns .name into an enum literal argument! Space before [ turns [0] into a block argument! | Keep . and [ tight: user.name, xs[0]. |
unexpected byte 59 (;) or double quotes "..." | C-style semicolons or double-quoted strings used in .vk source. | Use newlines between statements and '...' or `...` strings. |
2. ORO Mutability & Disjoint Field-Loan Diagnostics
Veko's One Reference Only (ORO) memory model requires mut at both the binding declaration and every mutating call site, and forbids aliasing the same mutable root twice in a single call:
// ERROR: variable 'buf' is immutable
buf = bytes/with-cap 16
bytes/push mut buf 10
// FIX: declare `mut buf` AND pass `mut buf`
mut buf = bytes/with-cap 16
bytes/push mut buf 10Disjoint Field Loans (mut s.rx vs mut s.tx)
Passing two distinct fields of the same struct (swap-bufs mut conn.rx mut conn.tx) is allowed at compile time because rx and tx are provably disjoint paths, whereas passing overlapping paths (merge mut conn.rx mut conn.rx or step mut conn mut conn.rx) is rejected to preserve single-owner aliasing guarantees.
Shared-Nothing spawn Isolation
// ERROR: cannot capture mutable binding 'counter' inside `spawn`
mut counter = 0
t = spawn [ counter = counter + 1 ]
// FIX: communicate via `chan/new` or return an owned value from `spawn`
t = spawn [ 1 ]
counter = counter + (task/await t)3. Gradual & --strict-types Diagnostics
Under veko check --strict-types (or strict-types = true in veko.vk), dynamic any values from untyped blocks, JSON payloads, or generic maps cannot flow implicitly into typed parameters (i64, str, u8, structs, or interfaces):
| Diagnostic | Cause | Idiomatic Fix |
|---|---|---|
dynamic any value flows to typed i64 | Passing untyped items[i] or json/decode field to an i64 parameter. | Convert explicitly with as-i64 val or str/to-i64/or s [0]. |
dynamic any value flows to typed str | Indexing an untyped block (lines[i]) where str is required. | Annotate block[str] on the producer (homogeneous literals [1 2 3] infer block[i64] automatically) or convert via str/append '' lines[i]. |
fallible T|err value flows to typed T without /or recovery or err? guard | Calling a fallible builtin (os/read-file, os/getenv, map/get, str/to-i64, str/index-of, first, last, pop, as-u8) and returning or passing the result directly as T. | Handle failure explicitly with /or [fallback] (e.g. os/getenv/or 'PORT' ['8080']) or narrow via if err? x [ return ... ]. |
strict-types: non-exhaustive match (add a '_' or 'else' catch-all arm) | A match expression over enums, integers, or strings lacks a wildcard _ or else fallback arm (except bool with both true and false). | Add _ [ default_expr ] or else [ default_expr ] as the final arm, and ensure all arms return compatible types. |
type mismatch in reassignment to mut x | Reassigning x = new_val where new_val's static type conflicts with mut x's initial binding type. | Keep mut locals single-typed across their lifetime or declare a new binding. |
type mismatch in return statement on if err? x [ return x ] | x has non-error static type T, which differs from outer return type U. | Propagate errors cleanly via /or: x = compute/or arg [e -> return e], or return (err (mold x)). |
member 'foo' missing for interface Bar | Passing a struct or map literal missing a required interface field or function signature. | Implement all fields/methods declared on the interface with matching types. |
4. .secret Firewall Diagnostics
Values typed secret str, secret bytes, or structs containing secret fields are tracked statically by types.vk and dynamically by the runtime .secret tag:
- Compile-time / runtime sinks blocked:
os/write-file,os/pwrite,net/write,json/encode,chan/send,spawncaptures, andffi/callall reject.secretvalues so credentials and cryptographic keys cannot be exfiltrated accidentally. - Display & template redaction:
print secret_val,mold secret_val, and`header={secret_val}`automatically redact to'<secret>'(and taint interpolated strings as.secret). - Explicit declassification: Only curated cryptographic boundaries (
crypto/seal,crypto/sha256,bits/ct-eq?) or masked UI (w/secret-input) operate on secrets directly.
5. Capability & Sandbox Confinement Diagnostics
Veko denies host ambient authority by default unless granted by veko.vk (allow-caps) or CLI flags (-A, -C):
| Error | Cause | Resolution |
|---|---|---|
capability denied: .net (or .fs, .ui, .exec) | Missing capability in veko.vk or CLI invocation. | Run veko mod sync to update allow-caps in veko.vk, or pass -C net / -A. |
capability denied: .ffi | Foreign shared library call attempted without opt-in .ffi or on --wasm. | Add .ffi to allow-caps (or -C ffi); note .ffi is permanently forbidden on --wasm. |
embed-str: path escapes workspace root | Compile-time embed-str / embed-bytes referenced .. or an absolute path outside the project. | Move the asset inside the workspace directory and reference it by relative path. |
path outside allowed root | Runtime .fs access attempted outside --allow-fs=<dir> canonical confinement. | Keep file paths inside the workspace or pass --allow-fs=<allowed_dir>. |
6. Reading Source-Mapped Stack Traces
Uncaught runtime errors include a source-mapped call trace (at <fn> (<file>:<line>)) pinpointing the exact call chain:
Uncaught error: err(upstream connection refused)
at fetch-cluster-state (src/client.vk:42)
at sync-dashboard (src/main.vk:19)Attach /or [e -> ...] at the boundary where you want to recover gracefully, or run veko inspect --bytecode src/main.vk to inspect the lowered OP-TRY-OR-PUSH handler ranges.