Errors

jiki provides structured error types for failures that occur during container operations. Each error type corresponds to a specific failure category, so you can catch and handle them individually.

Errors thrown by jiki extend a common JikiError base class with a code property for programmatic matching and a message string. Filesystem errors use Node.js conventions like ENOENT and EACCES.

Error types

Error ClassCodeDescription
FileNotFoundErrorENOENTThe specified file or directory does not exist
FileExistsErrorEEXISTA file or directory already exists at the path
PermissionErrorEACCESInsufficient permissions for the operation
ProcessErrorPROCESSA shell command or process exited with a non-zero code
TranspileErrorTRANSPILEesbuild failed to transform the code
NetworkErrorNETWORKA package download or registry request failed

Error fix suggestions

Parsed errors include an actionable suggestions array that helps users fix common mistakes:

import { parseError } from "@run0/jiki";

const err = parseError("runtime", new Error("Cannot find module 'react'"));
console.log(err.suggestions);
// ["Run: npm install react"]
Error PatternSuggestion
Cannot find module 'X'Run: npm install X
X is not defined (capitalized)Did you forget to import X?
Transpiler not initializedCall await container.init()
Sandbox path violationsAdd the path to sandbox.fs.allowedPaths
Network failures during installCheck your internet connection

ContainerError

interface ContainerError {
  id: string;
  category: "build" | "runtime" | "bundle" | "install" | "filesystem";
  title: string;
  message: string;
  file?: string;
  line?: number;
  column?: number;
  stack?: string;
  suggestions?: string[];
  timestamp: number;
}

Example

import { FileNotFoundError } from "@run0/jiki";

try {
  await container.readFile("/missing.txt");
} catch (err) {
  if (err instanceof FileNotFoundError) {
    console.log("File not found:", err.path);
  }
}