Version: dev

edit_error

Stable error · Editing

Tier: stable · Kind: error · Topic: Editing

JuliaTypeScriptPythonRustGo
EditErrornot exportednot exportedEditErrorEditError

Julia

struct EditError <: EarthSciASTError
EditError(msg::String)
EditError(msg)
EditError(msg)

Exception thrown when an editing operation cannot be applied — e.g. removing a variable, equation, reaction, event, or coupling entry that does not exist, or extracting a missing component. Throwing (rather than warning and returning the input unchanged) makes failed edits visible programmatically.

Source

Example (rename_variable)

renamed = rename_variable(model, "lambda", "k")
@assert parameters(renamed) == ["k"]
@assert to_ascii(renamed.equations[1]) == "D(N)/Dt = (-k) * N"

# Drop the half_life equation, then the variable it defined.
trimmed = remove_variable(remove_equation(model, 2), "half_life")
@assert unknowns(trimmed) == ["N"]
@assert length(trimmed.equations) == 1

# Editing a variable that does not exist raises an EditError.
try
    rename_variable(model, "nope", "k")
    error("expected an EditError")
catch e
    @assert e isa EditError
end

From docs/api/examples/julia/editing.jl

TypeScript

TypeScript does not export this error.

Python

Python does not export this error.

Rust

pub enum EditError {
    ComponentNotFound(String),
    InvalidOperation(String),
    VariableExists(String),
    EquationIndexError(usize),
    SpeciesNotFound(String),
    ReactionIndexError(usize),
    EventIndexError(usize),
    CouplingIndexError(usize),
}

Errors that can occur during editing operations

Source · Rust docs

Go

type EditError struct {
	Code    string
	Message string
}

func (e *EditError) DiagnosticCode() string

func (e *EditError) Error() string

EditError is the base diagnostic for a failed editing operation, and the error type for failures with no more specific type. It mirrors Julia’s catch-all EditError and Rust’s EditError enum.

Methods

func (e *EditError) DiagnosticCode() string

DiagnosticCode exposes the stable code.

func (e *EditError) Error() string

Source · Go docs