KScript docs
EN

Error types

The errors KScript throws, and the ones to throw or extend yourself. catch NotFound catches a NotFound and every type that extends it, and catch Error catches everything.

Declare your own with error PersonNotFound extends NotFound { id: int } and throw it with throw PersonNotFound(id: 42). A type with an HTTP status answers with that status when a route doesn't catch it. More in The language.

Error typeExtendsHTTP statusWhat it means
ErrorAny error. Every error type extends Error.
AIErrorA call to a language model that failed.
ArgumentErrorA call with the wrong arguments.
AssertionErrorA failed check in a test.
BadRequestError400A request that can't be handled as sent. Answers 400.
CancelledErrorThe script was stopped.
ConfigErrorA missing or invalid setting.
ConflictError409A change that clashes with the current state. Answers 409.
ForeignKeyViolationConflict409A save or delete that would leave a record pointing at one that isn't there. Answers 409.
UniqueViolationConflict409A save that would give two records the same value in a unique field. $err.fields names them. Answers 409.
ConnectionError503A database that can't be reached or opened. Answers 503.
ConstErrorChanging a const.
ContextErrorSomething used where it doesn't work.
ForbiddenError403A request the signed-in user isn't allowed to make. Answers 403.
FormatErrorText that isn't in the expected format, such as a date.
JsonFormatText that isn't valid JSON.
YamlFormatText that isn't valid YAML.
HttpErrorA mistake in a KScript.Http app, or a request that failed.
IOErrorReading or writing a file failed.
AccessIOThe operating system refused access to a file.
FileNotFoundIOA file or folder that doesn't exist.
PermissionIOA file outside the allowed folder, or a change to read-only files.
ImportErrorAn import that can't be found or a package that isn't imported.
InputErrorInput that couldn't be read.
InternalErrorA fault in KScript itself, not in the script.
JobFailedErrorA queued job that used up its tries. $err.cause is the last error.
LimitErrorA limit was reached, such as too much recursion.
MathErrorA calculation with no answer, such as dividing by zero, or maths in a document that can't be read.
MigrationErrorA migration that can't be read or run, or a kscript db command that can't go ahead.
NameErrorA name that doesn't exist: a variable, function, field or method.
NetworkErrorA request that failed or got an error status. $err.status is the status, when there is one.
TimeoutNetworkA request that took too long.
JobTimeoutTimeoutA queued job that ran longer than its timeout.
NotFoundError404Something that doesn't exist. Answers 404.
ModelNotFoundNotFound404A KScript.Data record that isn't in the database: ->find_or_fail() and ->first_or_fail(). $err.model and $err.id say which. Answers 404.
NullErrorUsing null where a value is needed.
PlatformErrorSomething this operating system can't do.
QueryErrorA database query that failed, or a condition that can't be turned into SQL.
MultipleRecordsFoundQuery->sole() found more than one row, when it expects exactly one.
ReferenceErrorA document that refers to a section, figure or source it doesn't have, or uses an id twice.
RetiredErrorA KScript 1 feature that KScript 2 doesn't have.
SyntaxErrorA script that can't be read: bad syntax, an unknown element or a misplaced one.
TooManyRequestsError429Too many requests in a short time, such as failed sign-ins. Answers 429, with Retry-After when the error has a retry_after field.
TypeErrorA value of the wrong type, such as text where a number is needed.
ShapeTypeData that doesn't fit a <type>. $err.problems lists each problem with its JSON path.
UIErrorA desktop window that can't be opened, such as on a machine without the window library.
UnauthorizedError401A request that needs someone to sign in. Answers 401.
ValidationError422Input that isn't valid. Answers 422 in a KScript.Http route.
ValueErrorA value that isn't allowed here.
IndexValueA position outside a list.