Kharat Bot Docs

KAL diagnostics & limits

Every error family with real codes, the diagnostic shape, and the complete table of runtime limits.

Reading a diagnostic#

Compile and runtime errors arrive in one shape:

text
{ code, message, line, column, hint }

The builder renders them as "Line L:C β€” message" plus the πŸ’‘ hint. Example: saving a script without the header yields E001_MALFORMED_VERSION_HEADER on line 1 with the hint to put KAL VERSION 2.0; first.

The error families#

FamilyWhereMeaning
E001–E003Version gateMissing/malformed header, unsupported version, source > 200k chars
E101–E301ParserSyntax errors with line/column
S001–S011SemanticsDeclarations, unresolved names, scopes, types, control flow, event context (S007), actions, schedules, rejected operators (S011)
V2_COMPILER_*Bytecode genInternal targets/statements that cannot compile
M001–M011ModulesImport problems β€” see Modules
VM*RuntimeSandbox violations during execution

Codes you will actually meet#

CodeWhat it meansTypical fix
E001_MALFORMED_VERSION_HEADERLine 1 is not KAL VERSION 2.0;Put the header on line 1 exactly
E101_SYNTAX_ERRORGrammar violationRead the line/column; check the statement's exact shape in these guides
S002_UNRESOLVED_IDENTIFIERUnknown nameDeclare it, or fix the spelling
S004_TYPE_MISMATCHWrong type for the positionAdjust the declared type or value
S007_INVALID_EVENT_CONTEXTVariable not available in this triggerUse only the trigger's context (see the table in Triggers)
S009_INVALID_SCHEDULEBad schedule formSCHEDULE EVERY <ms> or SCHEDULE AFTER "<dur>"
S011_UNSUPPORTED_OPERATORMATCHES/HAS_ROLE/HAS_PERMISSIONReplace with CONTAINS/IN over member.roles
M001_MODULE_NOT_FOUNDImport target not registeredSee Modules

Runtime (VM) errors#

At run time the sandbox enforces the budget:

CodeMeaning
EXECUTION_TIMEOUTThe 5-second wall clock expired
INSTRUCTION_LIMIT_EXCEEDEDMore than 50,000 VM instructions
CALL_DEPTH_LIMIT_EXCEEDEDRecursion past 64 frames
DIVISION_BY_ZERO/ or % by zero
TYPE_CHECK_FAILUREWrong operand types at runtime
STATE_ACCESS_ERRORState value not JSON-able or over its size limit
ACTION_EXECUTION_FAILUREA Discord action failed (carries the action type and line)
EXPLICIT_THROWA THROW was not caught

The complete limit table#

ResourceLimit
Source length200,000 characters
String literal65,536 characters
Identifier length128 characters
Tokens50,000
Parse depth256
VM instructions50,000
Wall clock5 seconds
Call depth64
Operand stack1,000
Array length10,000
Map entries10,000
String length at runtime1,000,000 chars
Discord actions per run5
Timeout duration28 days
Ban message-deletion window≀ 7 days (604,800 seconds)
Purge count1–100
Components5 rows Γ— 5; select menus ≀ 25 options; ids ≀ 100 chars; labels ≀ 80
State100 keys / 2,048-byte values / 512 KiB per script / keys ≀ 256 chars
Imports32 per script; modules 256 per server; module source 200,000 bytes
Active locks10,000
Rate buckets10,000

Debugging workflow#

  1. Check syntax in the builder β€” validate-only compile, no side effects.
  2. Run simulation β€” a sandboxed dry run with a mock user; inspect the recorded actions and any error.
  3. LOG / INSPECT β€” leave breadcrumbs in scripts under development: INSPECT result prints a structured dump of the value at that point.
  4. INTO capture β€” capture risky actions and branch on outcome.ok instead of letting failures crash the run.