mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
Keep error classes across links
Error responses now carry the registered name of the thrown error's class, and the requester rejects with an instance of that class instead of a generic RequestError. Error classes are registered like message classes, and plugins list their own in `errors`. RequestError is replaced by a hierarchy following the HTTP status codes: ClientError (ValidationError, ForbiddenError, NotFoundError, TimeoutError, ConflictError) and ServerError (InternalServerError). PermissionError is PermissionDeniedError and the config errors InvalidValue, InvalidField and InvalidAccess gain an Error suffix. Link logs only errors whose class is not registered. These arrive on the other side as InternalServerError with the original message and stack, so an error forwarded through the controller is logged once, where it was thrown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ffe82f81d8
commit
1c7c00b033
37 files changed
+589
-310
No files matched your search
@@ -305,6 +305,30 @@ The remaining uses of "control" for clusterioctl were renamed to "ctl":
|
||||
The term "control" is still used in message `src` and `dst` and in config field locations, where it covers both ctl and the web interface.
|
||||
|
||||
|
||||
## Request errors
|
||||
|
||||
`RequestError` is gone.
|
||||
Errors thrown by request handlers are now received by the requester as the same class, see [Request errors](/docs/writing-plugins.md#request-errors).
|
||||
Replace `RequestError` with the class that fits:
|
||||
|
||||
- Invalid input: `ValidationError`.
|
||||
- Operation disabled by config: `ForbiddenError`.
|
||||
- Missing instance, user, save etc.: `NotFoundError`.
|
||||
- Instance running, host not connected, name taken etc.: `ConflictError`.
|
||||
- Timeouts: `TimeoutError`.
|
||||
|
||||
`catch` blocks that check `err instanceof RequestError` should check `ClientError` instead, or the specific class.
|
||||
Checks of `err.code` for remote errors can use `instanceof`, e.g. `err instanceof lib.SessionLost`.
|
||||
|
||||
Other renames:
|
||||
|
||||
- `PermissionError` is `PermissionDeniedError`.
|
||||
- `lib.InvalidValue`, `lib.InvalidField` and `lib.InvalidAccess` are `lib.InvalidValueError`, `lib.InvalidFieldError` and `lib.InvalidAccessError`.
|
||||
|
||||
Errors of classes that are not registered, like a `TypeError` from a bug, are received as `InternalServerError`.
|
||||
Plugins that define their own error classes need to list them in `errors` of the plugin declaration.
|
||||
|
||||
|
||||
## Static assets in the web interface
|
||||
|
||||
`staticRoot` now includes the `static/` prefix.
|
||||
|
||||
@@ -223,7 +223,8 @@ Plugins may define their own requests as well.
|
||||
- `src: Address` - Responding endpoint.
|
||||
- `dst: Address` - Requester's address, including the original request ID.
|
||||
- `data.message: string` - Human-readable error description.
|
||||
- `data.code: string` (optional) - Error code.
|
||||
- `data.code: string` (optional) - Registered name of the error class, `<plugin>:<class>` for plugin errors.
|
||||
Missing or unknown names are received as `InternalServerError`.
|
||||
- `data.stack: string` (optional) - Error stack.
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user