agentsclimarketplace

Pike debugging

Skill TheSmuks/pike-ai-kb/skills/pike-debugging

How to diagnose Pike errors, introspect the runtime, navigate the stdlib source, and debug Pike code on the CLIFrom its SKILL.md

Install
npx -y skills add TheSmuks/pike-ai-kb --skill pike-debugging

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

6.9 KB, ~1.8k tokens by cl100k_base, as published. Nobody here has run it

Pike Debugging & Runtime Introspection Guide

Overview

Guide for diagnosing Pike compilation errors, runtime errors, and backtraces; navigating the standard library source; and using Pike's CLI and introspection tools to understand what's available. Target: Pike 8.0.1116.

Rules

Rule: Read the Error Message — Pike Tells You Exactly What's Wrong

Pike errors have precise location and type information. Do not guess — read the error output.

Compile-time errors (exit code 1 or 20):

-:4:Bad type in assignment.
-:4:Expected: int.
-:4:Got     : string(72..72).
Compilation failed.

Format: <file>:<line>:<message>. For -e scripts, file is -.

Runtime errors (exit code 10 or 21):

Division by zero.
/tmp/script.pike:5: /main()->main()

Format: <message>\n<location>: <program/object>-><method>().

Rule: Use compile_string for Syntax-Checking

pike -c does NOT exist. Use compile_string to verify code compiles:

mixed err = catch {
  program p = compile_string(code, "check");
};
if (err) {
  // Syntax error — describe_backtrace(err) gives details
}

Note: compile_string runs the preprocessor and full compilation. It will execute constant expressions but won't run create().

Rule: Error Values Have Three Shapes

mixed err = catch { /* code */ };
  1. err == 0 (zero_type == 1): No error occurred. Always check if (err) before inspecting.

  2. arrayp(err) == 1: Legacy format from error() and throw(({msg, backtrace()})).

    • err[0] — error message string
    • err[1] — backtrace array
    • Use describe_backtrace(err) for human-readable output
  3. objectp(err) == 1: Error.Generic or subclass (also arrayp!).

    • err->message() — error message string
    • err->backtrace() — backtrace array
    • Subclasses: Error.Math, Error.BadArgument, Error.Index, Error.Permission, Error.Resource, Error.Decode, Error.Compilation, Error.ModuleLoad
    • object_program(err) gives the specific error class
    • Check inheritance: Program.inherits(object_program(err), Error.Generic)

Always check objectp(err) first — Error.Generic objects are also arrayp. error("msg") produces legacy array format, not an Error.Generic object. Runtime errors (division by zero, index out of bounds) produce Error.Generic subclasses.

Rule: Format Strings Use Pike Specifiers, Not Python/JS

WRONG:   write(value)                       // not a generic print
WRONG:   write("hello " + name)             // works but no type safety
CORRECT: write("%O\n", some_value)          // inspect any value
CORRECT: write("Hello %s, age %d\n", name, age)  // typed formatting

Key format specifiers:

  • %O — readable dump of any value (most useful for debugging)
  • %t — type name only ("int", "string", "array", etc.)
  • %d — integer
  • %s — string
  • %f — float
  • %% — literal %

Rule: Do Not Guess at APIs — Use Runtime Introspection

Before using any function or class, verify it exists:

// Check if a module exists
mixed mod;
catch { mod = master()->resolv("ModuleName"); };
if (!mod) { /* module not available */ }

// List methods on an object
object f = Stdio.File();
array(string) methods = sort(indices(f));
// Note: sorted methods include underscore-prefixed internal methods first

// Get function type signature
typeof(Stdio.read_file)
// Returns: function(string, void | int, void | int : string(8bit))

// Get the class/program of an object
object_program(f)
// Returns: Stdio.File

// Check type at runtime
intp(x), floatp(x), stringp(x), arrayp(x), mappingp(x),
multisetp(x), objectp(x), programp(x), functionp(x)

Rule: pike -e Accepts Full Programs

pike -e compiles and runs Pike code — either a single expression or a full program with int main(). For multi-line scripts, a temp file is cleaner:

# Single expression
pike -e 'write("%O\n", indices(Stdio.File()));'

# Full program via -e
pike -e 'int main() { write("%O\n", indices(Stdio.File())); return 0; }'

# Multi-line — use a temp file
cat > /tmp/test.pike <<'EOF'
int main() {
  // your code here
  return 0;
}
EOF
pike /tmp/test.pike

Rule: Navigate the Module Source to Understand Behavior

Pike modules live in /usr/local/pike/8.0.1116/lib/modules/:

# Find the paths Pike uses
pike --show-paths

# List all available modules
ls /usr/local/pike/8.0.1116/lib/modules/*.pmod

# Read a module's source
cat /usr/local/pike/8.0.1116/lib/modules/Array.pmod | head -50

# C modules are .so files — their source is in the Pike source tree
# Pike source: src/modules/ or src/post_modules/

Module file conventions:

  • ModuleName.pmod — Pike module (source readable)
  • _ModuleName.so — C module (binary, source in Pike tree)
  • DirectoryName/ with module.pmod — directory-as-module

Rule: Common Error Patterns and Fixes

ErrorCauseFix
syntax error, unexpected TOK_*, expecting TOK_*Syntax mistake. Common: missing ;, wrong literal syntax, used [] instead of ({}) for arraysRead the line number. Check for ( before { in literals.
Bad type in assignment. Expected: X. Got: Y.Type mismatch in assignmentCheck what the RHS actually returns. Use %O to inspect.
Index 'X' is not present in module YFunction/class doesn't exist in that moduleUse master()->resolv() to check. Check spelling. Some functions are in _Module not Module.
Index Z is out of array rangeArray access out of boundsCheck sizeof() before indexing. Use negative indices: arr[-1] for last.
Division by zeroInteger or float division by zeroCheck divisor before dividing.
Cannot cast X to YInvalid type castNot all casts are valid. Use conversion functions instead.
Too few arguments to XMissing required argumentsCheck function signature. Use typeof() to see expected args.
Too many arguments to XExtra arguments passedCheck function signature. Some functions are variadic.
Undefined identifier: XVariable or function not declaredDeclare before use. Check scope. global prefix for module-level.
Attempting to index a non-indexed valueUsing [] or -> on a non-collectionCheck the value is actually an object/mapping/array before indexing.
Illegal character in programNon-ASCII or control character in sourceCheck encoding. Pike source should be UTF-8 or ASCII.

Additional References

What ships with it: 2 files

13.2 KB alongside SKILL.md

Keep looking

Skills are one crate of 326,851. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.