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 type | Extends | HTTP status | What it means |
|---|---|---|---|
Error | Any error. Every error type extends Error. | ||
AI | Error | A call to a language model that failed. | |
Argument | Error | A call with the wrong arguments. | |
Assertion | Error | A failed check in a test. | |
BadRequest | Error | 400 | A request that can't be handled as sent. Answers 400. |
Cancelled | Error | The script was stopped. | |
Config | Error | A missing or invalid setting. | |
Conflict | Error | 409 | A change that clashes with the current state. Answers 409. |
ForeignKeyViolation | Conflict | 409 | A save or delete that would leave a record pointing at one that isn't there. Answers 409. |
UniqueViolation | Conflict | 409 | A save that would give two records the same value in a unique field. $err.fields names them. Answers 409. |
Connection | Error | 503 | A database that can't be reached or opened. Answers 503. |
Const | Error | Changing a const. | |
Context | Error | Something used where it doesn't work. | |
Forbidden | Error | 403 | A request the signed-in user isn't allowed to make. Answers 403. |
Format | Error | Text that isn't in the expected format, such as a date. | |
Json | Format | Text that isn't valid JSON. | |
Yaml | Format | Text that isn't valid YAML. | |
Http | Error | A mistake in a KScript.Http app, or a request that failed. | |
IO | Error | Reading or writing a file failed. | |
Access | IO | The operating system refused access to a file. | |
FileNotFound | IO | A file or folder that doesn't exist. | |
Permission | IO | A file outside the allowed folder, or a change to read-only files. | |
Import | Error | An import that can't be found or a package that isn't imported. | |
Input | Error | Input that couldn't be read. | |
Internal | Error | A fault in KScript itself, not in the script. | |
JobFailed | Error | A queued job that used up its tries. $err.cause is the last error. | |
Limit | Error | A limit was reached, such as too much recursion. | |
Math | Error | A calculation with no answer, such as dividing by zero, or maths in a document that can't be read. | |
Migration | Error | A migration that can't be read or run, or a kscript db command that can't go ahead. | |
Name | Error | A name that doesn't exist: a variable, function, field or method. | |
Network | Error | A request that failed or got an error status. $err.status is the status, when there is one. | |
Timeout | Network | A request that took too long. | |
JobTimeout | Timeout | A queued job that ran longer than its timeout. | |
NotFound | Error | 404 | Something that doesn't exist. Answers 404. |
ModelNotFound | NotFound | 404 | A 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. |
Null | Error | Using null where a value is needed. | |
Platform | Error | Something this operating system can't do. | |
Query | Error | A database query that failed, or a condition that can't be turned into SQL. | |
MultipleRecordsFound | Query | ->sole() found more than one row, when it expects exactly one. | |
Reference | Error | A document that refers to a section, figure or source it doesn't have, or uses an id twice. | |
Retired | Error | A KScript 1 feature that KScript 2 doesn't have. | |
Syntax | Error | A script that can't be read: bad syntax, an unknown element or a misplaced one. | |
TooManyRequests | Error | 429 | Too many requests in a short time, such as failed sign-ins. Answers 429, with Retry-After when the error has a retry_after field. |
Type | Error | A value of the wrong type, such as text where a number is needed. | |
Shape | Type | Data that doesn't fit a <type>. $err.problems lists each problem with its JSON path. | |
UI | Error | A desktop window that can't be opened, such as on a machine without the window library. | |
Unauthorized | Error | 401 | A request that needs someone to sign in. Answers 401. |
Validation | Error | 422 | Input that isn't valid. Answers 422 in a KScript.Http route. |
Value | Error | A value that isn't allowed here. | |
Index | Value | A position outside a list. |