php-cooper

CooperError extends RuntimeException
in package

FinalYes

The one exception type every `cooper` failure mode throws -- lexing, parsing, literal validation, loop expansion, imports, merging, reference resolution, and `.env` loading alike -- so a caller only ever needs to catch one type.

Elixir's Cooper returns {:error, %Ichor.Error{stage: ...}} instead; throwing is simply idiomatic PHP (the same call php-dextrin makes for DXNError). $stage keeps the Elixir error's own vocabulary -- lexer, parser, action, loop, import, merge, resolve, dotenv -- so an error reads the same regardless of which port raised it.

$sourceLine/$sourceColumn locate lexer, parser, and literal errors in the CASC source (1-based); $sourceFile names the file the failing source came from, when it came from one (an entry file or one of its imports). They are separate from Exception's own getFile()/getLine(), which locate the PHP code that threw.

Table of Contents

Constants

STAGE_ACTION  : mixed = 'action'
STAGE_DOTENV  : mixed = 'dotenv'
STAGE_IMPORT  : mixed = 'import'
STAGE_LEXER  : mixed = 'lexer'
STAGE_LOOP  : mixed = 'loop'
STAGE_MERGE  : mixed = 'merge'
STAGE_PARSER  : mixed = 'parser'
STAGE_RESOLVE  : mixed = 'resolve'

Properties

$reason  : string
The error description alone, without the location suffix `getMessage()` appends when a line/column/file is known.
$sourceColumn  : int|null
$sourceFile  : string|null
$sourceLine  : int|null
$stage  : string

Methods

__construct()  : mixed
withFile()  : self
Returns a copy of this error attributed to `$file`, unless it already names one -- used when an error raised while parsing an imported file bubbles up through its importer.
format()  : string

Constants

STAGE_RESOLVE

public mixed STAGE_RESOLVE = 'resolve'

Properties

$reason read-only

The error description alone, without the location suffix `getMessage()` appends when a line/column/file is known.

public string $reason

$sourceColumn read-only

public int|null $sourceColumn = null

$sourceFile read-only

public string|null $sourceFile = null

$sourceLine read-only

public int|null $sourceLine = null

Methods

__construct()

public __construct(string $message, string $stage[, int|null $sourceLine = null ][, int|null $sourceColumn = null ][, string|null $sourceFile = null ][, Throwable|null $previous = null ]) : mixed
Parameters
$message : string

the error description, without location

$stage : string

which pipeline stage failed (one of the STAGE_* constants)

$sourceLine : int|null = null

1-based CASC source line, when known

$sourceColumn : int|null = null

1-based CASC source column, when known

$sourceFile : string|null = null

the CASC file the error occurred in, when known

$previous : Throwable|null = null

the underlying cause, if any

withFile()

Returns a copy of this error attributed to `$file`, unless it already names one -- used when an error raised while parsing an imported file bubbles up through its importer.

public withFile(string|null $file) : self
Parameters
$file : string|null

the file to attribute the error to

Return values
self —

the attributed copy (or $this, unchanged)

format()

private static format(string $message, int|null $line, int|null $column, string|null $file) : string
Parameters
$message : string
$line : int|null
$column : int|null
$file : string|null
Return values
string
On this page

Search results