tablo_core/declaration/kind.rs
1//! [`DeclarationErrorKind`]: every mistake a declaration can hold.
2
3use super::{
4 ActionInputFault, AreaFault, AuthMailFault, EditableColumnFault, FieldAccessFault,
5 FieldRuleFault, LocaleFault, ManyToManyFault, OidcFault, PolicyFault, ProfileFault,
6 RelatedFormFault, ResetFault, SegmentFault, ServeDirFault, SignUpFault, TenancyFault,
7 TenantProfileFault, TenantRegistrationFault, TwoFactorFault, VerificationFault,
8};
9
10/// What is wrong with a declaration.
11#[derive(Debug, Clone, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum DeclarationErrorKind {
14 /// The router holds no `toasty::Db`: call `.with(db)` before `.panel(..)`.
15 MissingDb,
16 /// Auth is on, but the `Db` does not register the shipped models it needs: `AuthSession`,
17 /// `AdminUser` for the shipped authenticator, `ColumnPreference` while a list has a
18 /// toggleable column, `AuthToken` for a feature that mails links or two-factor sign-in, and
19 /// `AuthFactor` for two-factor sign-in.
20 ///
21 /// Build the `Db` from `tablo::models!(..)`, add them to `toasty::models!(..)`, or opt out
22 /// with `.auth(Auth::disabled())`.
23 MissingAuthModels {
24 /// The unregistered models.
25 models: Vec<&'static str>,
26 },
27 /// `Panel::shell_assets` is set, but the router has no asset bundle: call `.assets(..)` first.
28 ShellAssetsWithoutBundle,
29 /// `Panel::notifications` on `Auth::disabled`, which signs nobody in to notify.
30 NotificationsWithoutAuth,
31 /// `Panel::require_model` names a model the `Db` does not register: add it to `models!(..)`.
32 UnregisteredModel {
33 /// The model, as Toasty names it: `AuditEntry`.
34 model: String,
35 },
36 /// `ResourceDef::requires_commit_hook` names a hook the panel does not run: register it.
37 MissingCommitHook {
38 /// The hook's type.
39 hook: &'static str,
40 },
41 /// A `Brand` color that is no hex color or plain color function, which the panel's stylesheet
42 /// would carry as it is.
43 ///
44 /// Spell it `#4f46e5` or `oklch(0.55 0.2 260)`.
45 BrandColor {
46 /// The refused value.
47 value: String,
48 },
49 /// A [`LoginThrottle`](crate::LoginThrottle) that allows no attempt, or counts over a window
50 /// of no time: either refuses every sign-in.
51 ThrottleAllowsNone {
52 /// The builder call that set it: `Auth::throttle`.
53 builder: &'static str,
54 },
55 /// `Auth::external` beside a feature that needs Tablo to own the account's credentials.
56 ///
57 /// Drop the feature: the host app signs its users in, and keeps their credentials.
58 ExternalAuthFeature {
59 /// The builder call the panel may not declare.
60 feature: &'static str,
61 },
62 /// A form declares a file field, but the panel installs no `Uploader` to store its bytes.
63 ///
64 /// Install one with `Panel::uploads` or `Panel::uploads_dir`.
65 FileFieldWithoutUploader {
66 /// The file field's name.
67 field: String,
68 },
69 /// A path segment the panel routes cannot be a literal URL segment.
70 ///
71 /// Pick a plain segment such as `blog-posts`.
72 InvalidSegment {
73 /// What names the segment: `panel prefix`, `ResourceDef::slug` or `PageDef::slug`.
74 item: &'static str,
75 /// The refused segment.
76 segment: String,
77 /// Why it is refused.
78 fault: SegmentFault,
79 },
80 /// The prefix overlaps Topcoat's runtime endpoints.
81 ///
82 /// Pick another prefix.
83 PrefixOverlapsRuntime {
84 /// The panel's prefix.
85 prefix: String,
86 },
87 /// The prefix overlaps another panel's.
88 ///
89 /// Give each panel a prefix of its own.
90 PrefixOverlapsPanel {
91 /// The other panel's prefix.
92 other: String,
93 },
94 /// A `Panel::host` that is not a bare host name or address.
95 ///
96 /// Name the host alone, without a scheme, a port, a path or a wildcard: `admin.example.com`.
97 InvalidHost {
98 /// The host as declared.
99 host: String,
100 },
101 /// A `Panel::endpoint` route outside Topcoat's runtime endpoints.
102 ///
103 /// Declare only shards and procedures; the panel's prefix guards its other routes.
104 EndpointOutsideRuntime {
105 /// The route's path.
106 path: String,
107 },
108 /// A directory the panel cannot serve.
109 ServeDir(ServeDirFault),
110 /// The panel's content security policy cannot be served.
111 ContentSecurityPolicy(PolicyFault),
112 /// A second `Panel::home` page.
113 ///
114 /// Keep one home page; register the other with `page`.
115 SecondHome,
116 /// Every resource declares [`without_navigation`](crate::ResourceDef::without_navigation) and
117 /// the panel has no home page, so its root, where a sign-in lands, leads nowhere.
118 ///
119 /// Show one resource in the sidebar, or register a page with `Panel::home`.
120 NoRoot,
121 /// The resource is registered on the panel twice.
122 ///
123 /// Register it once; mount a variant under its own type.
124 DuplicateResource,
125 /// The page is registered on the panel twice, `Panel::home` included.
126 ///
127 /// Register it once; mount a variant under its own type.
128 DuplicatePage,
129 /// The resource is not mounted on the context's panel.
130 ///
131 /// It refuses no mount: a request answers 500 when app code asks for a resource its panel
132 /// does not register, through [`wired_table`](crate::wired_table),
133 /// [`scoped_query`](crate::scoped_query), [`write_create`](crate::write_create) or
134 /// [`write_update`](crate::write_update). Register the resource on that panel, or reach it
135 /// through a context of a panel that does.
136 NotMounted,
137 /// A slug naming a route the panel serves itself: `login`, `logout`, `register`, `profile`,
138 /// `forgot-password`, `reset-password` or `-`.
139 ///
140 /// Rename it with `ResourceDef::slug` or `PageDef::slug`.
141 ReservedSlug {
142 /// The slug.
143 slug: String,
144 },
145 /// A slug another resource or page already mounts at.
146 ///
147 /// Give each a distinct slug.
148 DuplicateSlug {
149 /// The slug.
150 slug: String,
151 },
152 /// Two actions share a `NAME`.
153 ///
154 /// Rename one.
155 DuplicateAction {
156 /// The shared name.
157 name: &'static str,
158 },
159 /// Two widgets of a page, or of a resource's list, share a name.
160 ///
161 /// Give one a distinct [`WidgetDef::name`](crate::WidgetDef::name).
162 DuplicateWidget {
163 /// The shared name.
164 name: String,
165 },
166 /// A page's [filter](crate::PageFilter) shares its key with another, or its key is not a word
167 /// a query parameter carries: ASCII letters, digits, `-` and `_`.
168 ///
169 /// Give each filter a distinct key of those characters.
170 MisdeclaredPageFilter {
171 /// The key.
172 key: String,
173 },
174 /// A column cannot edit its field in a table's cell.
175 EditableColumn {
176 /// The column's name, which is its field's.
177 column: String,
178 /// What is wrong with it.
179 fault: EditableColumnFault,
180 },
181 /// An action's input cannot be served.
182 ActionInput {
183 /// The action's `NAME`.
184 action: &'static str,
185 /// What is wrong with it.
186 fault: ActionInputFault,
187 },
188 /// The panel's sign-up page cannot be served.
189 SignUp(SignUpFault),
190 /// The panel's profile page cannot be served.
191 Profile(ProfileFault),
192 /// An area cannot hold a page auth serves.
193 Area(AreaFault),
194 /// The panel's password reset cannot be served.
195 PasswordReset(ResetFault),
196 /// The panel's email verification cannot be served.
197 EmailVerification(VerificationFault),
198 /// The panel's tenant registration page cannot be served.
199 TenantRegistration(TenantRegistrationFault),
200 /// The panel's tenant settings page cannot be served.
201 TenantProfile(TenantProfileFault),
202 /// The panel's two-factor sign-in cannot be served.
203 TwoFactor(TwoFactorFault),
204 /// The panel's provider sign-in cannot be served.
205 Oidc(OidcFault),
206 /// The panel's auth mail cannot be sent.
207 AuthMail(AuthMailFault),
208 /// The panel's locales or translations cannot be served.
209 Locale(LocaleFault),
210 /// Two relations to the same resource.
211 ///
212 /// Keep one.
213 DuplicateRelation,
214 /// A relation to a resource the panel does not register.
215 ///
216 /// Register the related resource.
217 UnregisteredRelation,
218 /// A `has_one` relation declared as a tab: its form edits inside the record's own form.
219 ///
220 /// Drop `Relation::tab`.
221 HasOneTab,
222 /// A relationship field, or a relationship filter, whose options come from a resource the
223 /// panel does not register.
224 ///
225 /// Register that resource.
226 UnregisteredOptionSource {
227 /// The field.
228 field: String,
229 /// The option source's type.
230 source: &'static str,
231 },
232 /// A relation column labelling its records by a resource the panel does not register:
233 /// `RelationColumn::{new, of, list}::<R>` or `CountColumn::of::<R>`.
234 ///
235 /// Register `R`, or use `RelationColumn::unscoped` for a model no resource administers.
236 UnregisteredLabelSource {
237 /// The column.
238 column: String,
239 /// The label source's type.
240 source: &'static str,
241 },
242 /// A `CountColumn` over a relation whose records' primary key spans several columns, which
243 /// its count query cannot match a row's related records by.
244 ///
245 /// Key the related model by one column, or count in a `ComputedColumn`.
246 CompositeKeyCount {
247 /// The column.
248 column: String,
249 },
250 /// A lens with more than one step where a single field of the model is needed.
251 ///
252 /// Name one field of the model.
253 TraversalLens {
254 /// The lens's step count.
255 steps: usize,
256 },
257 /// A multi-step lens that resolves to no single column.
258 ///
259 /// Step only through embedded structs, enum variant fields and `#[document]` fields.
260 UnresolvedLens {
261 /// The lens's model.
262 model: &'static str,
263 /// The lens's field indices, step by step.
264 steps: Vec<usize>,
265 },
266 /// A model whose schema no driver compiles, so its embedded paths name no column. The error
267 /// gives the reason of each of Toasty's PostgreSQL, SQLite, MySQL and DynamoDB drivers.
268 ///
269 /// Fix the model for your driver.
270 Uncompiled {
271 /// The model.
272 model: &'static str,
273 /// Each driver's reason to refuse it.
274 error: String,
275 },
276 /// A resource's tenancy that cannot scope its rows.
277 Tenancy {
278 /// What is wrong.
279 fault: TenancyFault,
280 },
281 /// A field access that cannot hide its field everywhere the panel shows it.
282 FieldAccess {
283 /// What is wrong.
284 fault: FieldAccessFault,
285 },
286 /// A table with no column.
287 ///
288 /// Declare columns; a resource whose model's table lists nothing declares its own `table`.
289 NoColumns,
290 /// `Table::page_size(0)`.
291 ///
292 /// Pass a page size of at least 1.
293 ZeroPageSize,
294 /// `Table::default_sort_by` names no sortable column.
295 ///
296 /// Declare its column `.sortable()`.
297 UnsortableDefaultSort {
298 /// The named column.
299 column: String,
300 },
301 /// Two table columns share a name.
302 ///
303 /// Rename one.
304 DuplicateColumn {
305 /// The shared name.
306 name: String,
307 },
308 /// Two table filters share a name.
309 ///
310 /// Rename one.
311 DuplicateFilter {
312 /// The shared name.
313 name: String,
314 },
315 /// Two list tabs share a key.
316 ///
317 /// Give each [`ListTab`](crate::ListTab) a distinct key.
318 DuplicateTab {
319 /// The shared key.
320 key: String,
321 },
322 /// A table offers two groupings by one field.
323 ///
324 /// Declare each [`Table::group_by`](crate::Table::group_by) once.
325 DuplicateGrouping {
326 /// The field's name.
327 name: String,
328 },
329 /// A table filter's name holds a `.`, which its URL parameters reserve for a part:
330 /// `f.<name>.<part>`.
331 ///
332 /// Rename it without the `.`.
333 DottedFilterName {
334 /// The name.
335 name: String,
336 },
337 /// A select filter option whose value the field's type does not parse, so choosing it
338 /// filters nothing.
339 ///
340 /// Spell it as the field's form value, or build the filter with `SelectFilter::of`.
341 UnparsedFilterOption {
342 /// The filter's name.
343 filter: String,
344 /// The option's value.
345 value: String,
346 },
347 /// An option of [`Table::option_tabs`](crate::Table::option_tabs) whose value the field's
348 /// type does not parse, so its tab admits no row.
349 ///
350 /// Spell the option as the field's form value.
351 UnparsedTabOption {
352 /// The option's value.
353 value: String,
354 },
355 /// Two schema fields share a name.
356 ///
357 /// Bind each input to a distinct field.
358 DuplicateField {
359 /// The shared name.
360 name: String,
361 },
362 /// A field disabled or hidden on the create form, or one a condition can disable, with no
363 /// `default` and no blank answer: a create could not fill it.
364 ///
365 /// Give it a `default`, make it optional, or use `disabled_on_edit`.
366 DisabledWithoutValue {
367 /// The disabled field.
368 field: String,
369 },
370 /// A repeater's item disables one of its row's controls or gives it a default, which a row
371 /// does not apply.
372 ///
373 /// Disable the repeater's own field.
374 RepeaterLeafModifier {
375 /// The repeater.
376 field: String,
377 /// The control in its row.
378 leaf: String,
379 },
380 /// A repeater's item has a password control, which an edit cannot render back, so every save
381 /// would overwrite the stored secret.
382 ///
383 /// Keep the secret out of the repeater's item.
384 RepeaterPassword {
385 /// The repeater.
386 field: String,
387 /// The password control in its row.
388 leaf: String,
389 },
390 /// A text field's declared length, bounds or pattern cannot work.
391 FieldRule {
392 /// The field, or `repeater.leaf` for a control in a repeater's rows.
393 field: String,
394 /// What is wrong.
395 fault: FieldRuleFault,
396 },
397 /// A field's default is a value its control never posts: one its type does not parse, one
398 /// not among a choice's options, or a list or one value where the control posts the other.
399 ///
400 /// Spell the default as the field's form value, a list for a multiple choice.
401 UnpostedDefault {
402 /// The field.
403 field: String,
404 /// The default, a list spelled `["a", "b"]`.
405 value: String,
406 },
407 /// A condition watches a field the schema does not place.
408 ///
409 /// Place the watched field in the same schema.
410 UnplacedWatchedField {
411 /// The watched field.
412 field: String,
413 },
414 /// A condition watches a field that another condition hides while what it guards still
415 /// shows.
416 ///
417 /// Place the guarded field inside the block that hides the watched one.
418 HiddenWatchedField {
419 /// The watched field.
420 field: String,
421 },
422 /// A condition, or a dependent choice, watches a field a condition disables, which posts
423 /// nothing while it is disabled: the browser would follow the value the user last chose, the
424 /// server the stored one or the default.
425 ///
426 /// Watch another field, or drop `disabled_when` from the watched one.
427 DisabledWatchedField {
428 /// The watched field.
429 field: String,
430 },
431 /// A condition names a value its watched field never posts: not one of a choice's options, or
432 /// neither `true` nor `false` for a toggle.
433 ///
434 /// Name one of its options, or `true` or `false` for a toggle.
435 UnpostedConditionValue {
436 /// The watched field.
437 field: String,
438 /// The value.
439 value: String,
440 },
441 /// A dependent choice's column belongs to another model than its relationship's source, or
442 /// the choice has no relationship.
443 ///
444 /// Declare `relationship::<R>()`, and name a column of `R`'s model in `depends_on`.
445 MisdeclaredDependentChoice {
446 /// The dependent choice.
447 field: String,
448 },
449 /// A choice whose [`options_where`](crate::ChoiceField::options_where) narrows no
450 /// relationship: declare `relationship::<R>()`, or drop `options_where`.
451 UnfilterableChoice {
452 /// The filtered choice.
453 field: String,
454 },
455 /// A dependent choice that takes several options, or that depends on one that does: a
456 /// multiple choice's key holds a list, which narrows nothing.
457 ///
458 /// Drop `depends_on` or `multiple`.
459 MultipleDependentChoice {
460 /// The dependent choice.
461 field: String,
462 },
463 /// A dependent choice rendered as [radios](crate::ChoiceField::radio) or
464 /// [buttons](crate::ChoiceField::buttons): the browser lists its options once, so it cannot
465 /// narrow them when the parent changes.
466 ///
467 /// Drop `depends_on`, or `radio` or `buttons`.
468 ListedDependentChoice {
469 /// The dependent choice.
470 field: String,
471 },
472 /// A [creatable](crate::ChoiceField::creatable) choice that is not a single select over a
473 /// resource's records: a multiple choice, radios or buttons, a dependent or filtered choice, a
474 /// source that is not a resource, no relationship, or a choice in a repeater's rows.
475 ///
476 /// Drop `creatable`, or declare the choice as a single select with `relationship::<R>()` over
477 /// a resource `R`.
478 UncreatableChoice {
479 /// The creatable choice: `repeater.leaf` for one in a repeater's rows.
480 field: String,
481 },
482 /// A dependent choice depends on a field the schema does not place.
483 ///
484 /// Place that field in the same schema.
485 UnplacedParentField {
486 /// The dependent choice.
487 field: String,
488 /// The field it depends on.
489 parent: String,
490 },
491 /// A field a condition hides has no blank answer, so a submission hiding it cannot parse.
492 ///
493 /// Make it an `Option`, or give it `#[form(blank = ..)]`.
494 RequiredConditionalField {
495 /// The field.
496 field: String,
497 },
498 /// A record-form field binding a key no control posts, after the form renders every field
499 /// it does not place: a hand-written [`RecordForm::control`](crate::RecordForm::control)
500 /// that renders no control for it.
501 ///
502 /// Render the field's control.
503 MissingControl {
504 /// The record-form field.
505 field: String,
506 /// The key it binds.
507 key: String,
508 },
509 /// A tenant-scoped resource's record form claims the tenant column.
510 ///
511 /// Drop the field: the framework stamps the tenant.
512 FormClaimsTenantColumn {
513 /// The record-form field.
514 field: String,
515 /// The tenant column.
516 column: String,
517 },
518 /// A soft-deleting resource's record form claims the soft-delete column, which only a delete
519 /// and a restore write.
520 ///
521 /// Drop the field, or mark it `#[form(skip)]` on a `ModelForm`: only a delete and a restore
522 /// write the column.
523 FormClaimsSoftDeleteColumn {
524 /// The record-form field.
525 field: String,
526 /// The soft-delete column.
527 column: String,
528 },
529 /// A form field named after a key the form's POST carries itself: the CSRF token, the edit
530 /// form's `record_version`, or the create form's `create_another`.
531 ReservedFormField {
532 /// The field.
533 field: String,
534 },
535 /// A choice field with neither options nor a relationship.
536 ///
537 /// Declare `.options(..)`, `.relationship::<R>()`, or `#[form(relationship = R)]`.
538 EmptyChoice {
539 /// The field.
540 field: String,
541 },
542 /// A relationship field, or a relationship filter, over a model with a composite primary key.
543 ///
544 /// Choose over a model with a single-column key.
545 CompositeKeyChoice {
546 /// The field, or the filter's name.
547 field: String,
548 },
549 /// A field marked unique over a column no unique index covers.
550 ///
551 /// Add `#[unique]` to the model, or drop `.unique()`.
552 UniqueWithoutIndex {
553 /// The field.
554 field: String,
555 },
556 /// A unique field whose non-nullable column stores one value for every empty submission.
557 ///
558 /// Make the field required, or an `Option`.
559 OptionalUnique {
560 /// The field.
561 field: String,
562 },
563 /// [`create_column`](crate::ResourceDef::create_column) names the tenant column.
564 ///
565 /// Drop it: the framework stamps the tenant.
566 CreateColumnsNameTenant {
567 /// The tenant column.
568 column: String,
569 },
570 /// A non-nullable column nothing writes on create, for a resource that serves a create page:
571 /// not the form, not a Toasty `#[default(..)]`, not the tenant stamp, not a `create_column`.
572 ///
573 /// Add the field to the form, a default to the model, or a `create_column`; or turn the
574 /// create page off with `without_page(ResourcePage::Create)`.
575 UnwrittenColumn {
576 /// The column.
577 column: String,
578 },
579 /// [`importable`](crate::ResourceDef::importable) on a resource that serves no create page:
580 /// it has no record form, or turns the page off with
581 /// [`without_page`](crate::ResourceDef::without_page).
582 ///
583 /// Drop `importable`, or serve the create page.
584 ImportWithoutCreate,
585 /// A detail listing no column on a resource that serves the view page.
586 ///
587 /// Declare a [`detail`](crate::ResourceDef::detail) or a table, or turn the page off with
588 /// `without_page(ResourcePage::View)`.
589 EmptyDetail,
590 /// A `has_one` relation whose related form cannot render inside the owner's form.
591 RelatedForm(RelatedFormFault),
592 /// A many-to-many field or relation whose join model cannot link records.
593 ManyToMany {
594 /// The field, or the relation's `via` field.
595 field: String,
596 /// What is wrong.
597 fault: ManyToManyFault,
598 },
599}