UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

133 lines • 6.15 kB
export { PipeClosed } from '../io/errors.ts'; import type { ByteSource } from '../io/types.ts'; import type { ArithWrite } from './types.ts'; /** * A bash arithmetic syntax or evaluation error, worded as bash's line: the * expression, what went wrong, and the text from the token the reader * stood on to the end (`1+: syntax error: operand expected (error token is * "+")`). `writes` carries the assignments the expression made before it * failed: bash binds each at once, so `x=5, 1/0` leaves `x` at 5 and * `RANDOM=42, RANDOM + 1/0` leaves the generator seeded and drawn from. * The evaluator fills it as it throws; a caller lands them the way it * lands a successful result's, then reports the error. `inSubscript` * marks one made while an array subscript evaluated, which ends the shell * wherever the subscript is (`let 'a[1+]'`), where `let` would otherwise * fail with 1. Mirrors Python's mirage.shell.errors.ArithError. */ export declare class ArithError extends Error { readonly reason: string; readonly expression: string; readonly token: string | null; writes: ArithWrite[]; inSubscript: boolean; constructor(reason: string, expression?: string, token?: string | null); /** * How the error unwinds where no status answers it: one in a subscript, * or in an `-i` value (`fatal`), ends the shell with 1; any other * discards the line, as `$((1/0))` does. The command the error belongs * to leads the line (`bash: read: 1+: ...`, `bash: x: 1/0: ...` for * `${x:1/0}`), except one in a subscript, which bash names by the * subscript alone. */ signal(cmd?: string, fatal?: boolean): ExitSignal; } /** * An assignment to a readonly shell variable: a session write to a name * `readonly` marked, or one an arithmetic expression made. Its message is * bash's `<name>: readonly variable`, which each caller renders in its own * voice. An arithmetic evaluation stops at it, as bash's does: `writes` * carries the assignments made before it, which bind (`(( X=5, R=3 ))` * leaves X at 5), and nothing after it runs. `inSubscript` marks one made * while an array subscript evaluated (`${a[R=3]}`, `(( a[R=3] ))`), which * ends the shell wherever the subscript is. Mirrors Python's * mirage.shell.errors.ReadonlyVariableError. */ export declare class ReadonlyVariableError extends Error { readonly varName: string; readonly inSubscript: boolean; writes: ArithWrite[]; constructor(name: string, inSubscript?: boolean); /** * How the error unwinds where no status answers it: one in a subscript, * or in an `-i` value (`fatal`), ends the shell with 1; any other * discards the line, as `$((R=3))` does. */ signal(fatal?: boolean): ExitSignal; } export declare class ExitSignal extends Error { exitCode: number; stderr: Uint8Array; stdout: Uint8Array | null; containedCode: number; expanding: number | null; replaced: string | null; unrouted: boolean; cleanup: Uint8Array; sourced: boolean; constructor(exitCode?: number, stderr?: Uint8Array, stdout?: Uint8Array | null, containedCode?: number | null); } /** * An error after which bash discards the rest of the line. A bad * substitution, an arithmetic or assignment error, a write the shell refuses: * the command never runs, and neither do the statements after it on its line, * but the next line does, with `$?` at 1. The line loop of a shell, of `eval` * and of `source` resumes there; a child shell ends on it with status 1, and * so does `set -e`. `containedCode` is the status a `( )` subshell, or a * compound command forked as a stage or job, ends with when the error * reaches it rather than a line loop: 2 for a refused `${var:=word}`, 1 for * any other. Mirrors Python's mirage.shell.errors.DiscardSignal. */ export declare class DiscardSignal extends ExitSignal { constructor(stderr?: Uint8Array, containedCode?: number); } /** * A glob that matches more paths than its mount's `walkLimit`. A command * it is a word of does not run, as exec(2) refuses an argument list too * long; anywhere else (a `for` list, a redirect) the line is discarded like * any expansion error. `reason` is the limit's line. Mirrors Python's * mirage.shell.errors.TooManyMatches. */ export declare class TooManyMatches extends DiscardSignal { readonly reason: string; constructor(reason: string); } /** * `set -u` reading a name that is not set: `$x`, `${a[i]}`, or a variable * an arithmetic expression reads. GNU bash dies on it the way it dies on * `${x:?}`: status 127 at top level, 1 from a containing subshell or * pipeline segment. Mirrors Python's mirage.shell.errors.UnboundVariable. */ export declare class UnboundVariable extends ExitSignal { constructor(name: string); } /** * A `${...}` bash cannot read, found as its word expands. bash names the text * of the expansion it was running: the whole word, a double-quoted part's * inside, an operator's word, an arithmetic expression, a heredoc's body. * Each level the error leaves renames it (`within`) until one of those fixes * the name. Mirrors Python's mirage.shell.errors.BadSubstitution. */ export declare class BadSubstitution extends DiscardSignal { private fixed; constructor(text: string); /** Name the word being expanded, unless a boundary already has. */ within(word: string, fixed?: boolean): this; } /** * Await an expansion of `word`, which a bad substitution names: a * double-quoted part's inside, an operator's word, an arithmetic expression. * Mirrors Python's mirage.shell.errors.named. */ export declare function named<T>(word: string, pending: Promise<T>): Promise<T>; /** * `return` unwinding to the function or sourced file it ends; `stdout` is the * output the constructs it left had produced before it. */ export declare class ReturnSignal extends Error { readonly exitCode: number; stderr: Uint8Array; stdout: ByteSource | null; unrouted: boolean; constructor(exitCode: number, stderr?: Uint8Array, stdout?: ByteSource | null); } //# sourceMappingURL=errors.d.ts.map