# Compile errors and warnings

Every error and warning of the Lithe compiler, by the step that reports it. In the messages below, words like `tag`, `name` or `path` stand for what the code holds.
The errors of the Kotlin compiler are its own and aren't listed here. The messages of the site build, the dev server and the running app are in
[Build, dev server and runtime errors](/docs/reference/build-errors).


A diagnostic of the compiler names the file, line and column. Lines and columns start at 1, and a tab counts as one column:

```text
app/src/App.lithe:12:8: `@catch` takes the name of the error, write `@catch (e) { }`
app/src/App.lithe:4:2: warning: `total` is never used
```

- A [site build](/docs/sites/static-sites) prints them in its log, the [dev server](/docs/sites/dev-server#error-panel) lists them in the browser, and an
  [editor](/docs/tooling/editors) shows them as you type.
- An error stops the build, a warning doesn't.
- The compiler reports an error where it happens and goes on, so one run reports several, in source order. The only exception is a Kotlin fragment that
  never closes, `{` without its `}`: the compiler stops there, because nothing after it can be trusted.

## Syntax

### Script block

| Message | Cause |
|---------|-------|
| `<script kotlin>` goes at the top level of the file | The block is inside an element or a block of the markup. |
| only one `<script kotlin>` block is allowed | The file has a second one. |
| `<script kotlin>` takes no other attribute | An attribute sits next to `kotlin`. |
| imports go at the top of `<script kotlin>` | An `import` comes after other code. |
| `package` isn't possible in `<script kotlin>` because the package comes from the folder of the file | The script declares a package. |
| a prop is written `prop val name: Type`, its name an identifier | A `prop val` or `prop var` line has no plain name. |
| a prop needs a type, write `prop val name: Type` | The prop has no `: Type`. |
| the default value continues on the next line, wrap it in parentheses | A default value spans two lines. |
| props are declared at the top level | A prop is declared inside a function, a class or a block. |
| a component has one `*prop`, which receives every attribute no other prop takes | A second `*prop`. |
| a `*prop` is a `val` because the parent builds what it holds | `*prop var`. |
| a `*prop` takes no default because it is empty when the parent gives nothing | A `*prop` with `=`. |
| a `*prop` is typed with the element that takes the attributes, such as `Attributes<HTMLButtonElement>` or `Attributes<HTMLElement>` | Any other type. |
| `{*name}` holds the attributes of `<tag>`, which `<other>` doesn't take | The rest prop is spread on an element of another type. |

### Brackets and strings

These come from reading the Kotlin of the script and of the markup.

| Message | Cause |
|---------|-------|
| `bracket` is never closed | A `{`, `(`, `[` or string has no end. |
| expected `bracket` but found `other` | A closing bracket doesn't match the one that is open. |
| unexpected `bracket` | A closing bracket has no opening one. |
| expected `character` | A character the syntax needs is missing, like the `>` of a tag. |

### Tags

| Message | Cause |
|---------|-------|
| `<tag>` is a void element, it has no end tag | An end tag follows an element like `<br>` or `<img>`. |
| stray `</tag>` | An end tag closes nothing. |
| `<tag>` is never closed | An element or a component has no end tag. |
| the tag is never closed, expected `>` | The file ends inside a tag. |
| `name` isn't a valid tag name | An element name holds `_`, or a component name holds `-`. |
| the comment is never closed | `<!--` has no `-->`. |
| unknown character reference `&name;` | The entity isn't one of HTML. |
| the name of a `<{...}>` tag can't be empty | `<{}>` holds no expression. |
| `@raw` isn't possible on `<{...}>` | A [dynamic tag](/docs/components/markup#dynamic-tags) takes no raw content. |
| only one `<style>` block is allowed | The file has a second `<style>`. |
| only one `<style global>` block is allowed | The file has a second `<style global>`. |
| `<page>` goes at the top level of the file | The [page options](/docs/sites/kobweb#page-options) are inside an element or a block. |
| only one `<page>` is allowed | The file has a second `<page />`. |
| `<page>` holds nothing, write `<page ... />` | `<page>` has content or an end tag. |
| `<page>` takes `prerender={false}`, `route="..."` and `layout="..."`, as written values | Another attribute, or a value computed by Kotlin. |
| `<page>` belongs to a file of the package `group.pages` | The Gradle plugin compiles a file outside the pages of the Kobweb site that has a `<page />`. |
| `<page>` is read by the pages of a Kobweb site only | A Lithe site, or a Gradle site without Kobweb, has a file with a `<page />`. |
| `name:` isn't a valid tag name | A tag name has a `:`. |

### Attributes and expressions

| Message | Cause |
|---------|-------|
| an expression can't be empty, a literal brace goes in a `@raw { }` block | `{}` in the markup. |
| unexpected `character` in a tag | A character that can't start an attribute. |
| the attribute value is never closed | A quote has no end. |
| a braced attribute is a plain name, `::name` or `*expr`, write `name={expr}` for an expression | `{a.b}` is used as an attribute. |
| expected an attribute name after `@` | `@` is alone in a tag. |
| `@name` needs a value, write `={...}` | An event or directive has no `={ }`. |
| expected `{` | The value of an event or directive isn't in braces. |
| `@event={name}` reads `name` without calling it, write `@event={name()}`, or `@event={::name}` for a function that takes the event | A handler is a name alone, which would never run. |
| `@ref` takes the variable that holds the element, write `@mount={ }` to run code with it | `@ref` is given a lambda with parameters. |

### Blocks

| Message | Cause |
|---------|-------|
| `{` is never closed | A block has no `}`. |
| expected `(` after `@keyword` | `@if`, `@for`, `@when` or `@key` has no parentheses. |
| a `@for` header is `item in items` | The header has no `in`. |
| only `key = ...` can follow the loop header | `@for (x in y, ...)` holds something else than a key. |
| `@else` has no `@if` before it, and a `@for` only takes `@else { }` | A stray `@else`. |
| `@pending` has no `@await` before it | A stray `@pending`. |
| `@catch` has no `@await` or `@try` before it | A stray `@catch`. |
| `@catch` of a `@try` names the error and the function that tries again, write `@catch { error, retry -> }` | The head names more than two things, or something that isn't a name. |
| `@try` isn't possible in `<head>`, put the `<head>` in a component inside the `@try` | A `@try` inside `<head>`. |
| duplicate `@pending` | An `@await` has two. |
| duplicate `@catch` | An `@await` has two. |
| `@catch` takes the name of the error, write `@catch (e) { }` | The parentheses don't hold a name. |
| a branch of `@when` is written `condition -> { }` | A branch has no arrow or no braces. |
| local markup is written `@fun name(value: Type) { }` | An `@fun` has no name or parentheses. |
| a parameter of `@fun` needs a type, write `name: Type` | A parameter has no type. |
| a local value is written `@val name = value`, or `@val name: Type = value` | An `@val` has no name or value. |
| the value of `@val` continues on the next line, wrap it in parentheses | The value spans two lines. |
| `@name { }` fills a children prop of a component, it only works between the tags of a component | A fill sits elsewhere. |

## Components and markup

### Names and props

| Message | Cause |
|---------|-------|
| the file name `name` must be an uppercase identifier because it names the component | Like `my-card.lithe` or `card.lithe`. |
| `name` is reserved by the runtime, rename the file | The name is one of `Text`, `Element`, `ClonedElement`, `StaticHtml`, `Comment`, `RawElement`, `Choose`, `Each`, `Key`, `Await`, `Head`, `Ui`, `Markup`. |
| duplicate prop `name` | Two props share a name. |
| a children prop can't be called `name` because `@name` is a block, rename it | A `@Markup` prop is called `key`, `await`, `pending`, `catch`, `html` or `raw`. |
| `onNameChange` is the change callback generated for `prop var name` | A prop has the name of a generated callback. |
| `attribute={value}` can't bind: only a `prop var`, a `var` by `state` or `derived`, or such a property of a class or `object` the compiler can tell from the receiver, is bound | The target of a [binding](/docs/components/bindings) can't be written. |

### Using components

| Message | Cause |
|---------|-------|
| `{*...}` isn't possible on a component because a component is not an element | A spread on a component. |
| `name` isn't possible on a component because a component is not an element | `@ref`, `@mount`, `style={...}` or `@raw` on a component. |
| `name` isn't a valid prop name because a prop is a Kotlin identifier | Like `data-id` on a component. |
| `name` is filled twice | Two `@name { }` blocks. |
| `name` is given both as an attribute and as a fill | The prop gets two values. |
| the default children are given twice, by a `{ params -> }` lambda and by loose content | Both forms between the tags. |
| duplicate attribute `name` | The same attribute twice on a tag. |
| `<Name>` has no prop `attribute`, and `<tag>`, which takes its other attributes, has no attribute of that name | An unknown name given to a component with a [rest prop](/docs/components/files#rest-prop). |
| `rest` is given by name, so `<Name>` takes no other attribute for it | The rest prop is passed and loose attributes too. |
| `attribute` can't be bound because `<Name>` has no prop of that name, and attributes of a `*prop` are only read | `{::name}` for an attribute that goes to the rest prop. |

### Local markup and variable tags

| Message | Cause |
|---------|-------|
| `@fun name` is declared twice in the same block | Two local markups share a name. |
| local markup can't be called `name` because `@name` is a block, rename it | An `@fun` is called `key`, `await`, `pending`, `catch`, `html` or `raw`. |
| `@name(...)` renders a prop or a `@fun`, and none is named `name` here | Nothing of that name is in scope. |
| `@name` renders markup with parentheses, write `@name()` | A prop or `@fun` is written without parentheses. |
| `@fun first` and `@fun second` can't render each other because Kotlin local functions only see the ones above them | Two local markups call each other. |
| `@name` renders here, above a `@val` that `@fun name` needs, move the `@val` up | The call sits above a value the `@fun` reads. |
| `<name>` can't render `name` because only a `@fun` or a name declared with a `@Markup` or `@Composable` type is rendered by a tag | A lowercase tag names a variable that isn't markup. |
| `<name>` composes into a `<div>`, which can't sit inside `<p>` or directly in a table part | A tag of a composable sits where its `<div>` host can't. |
| `<name>` calls the variable `name`, so it takes no content | A variable tag has children. |
| `{*...}` isn't possible on `<name>` because it calls a variable, which takes its attributes as arguments | A spread on a variable tag. |
| `name` isn't possible on `<name>` because it calls a variable, which takes its attributes as arguments | `@ref` or `@mount` on a variable tag. |
| `@html` must be the only child of an element because it replaces the whole content of that element | `@html(...)` sits next to other content. |

## HTML structure

The browser parses the server page before the client hydrates it, so markup it would rearrange is an error. These messages end with
`so the page would not match what was rendered`. When the markup sits in a `@fun` and only the place of a call makes it wrong, the message is at that call
and starts with ``in `@name`,``.

| Message | Cause |
|---------|-------|
| `<tag>` can't sit inside another `<tag>` because the browser splits them | `<a>`, `<button>` or `<form>` inside itself. |
| `<tag>` can't sit inside `<p>` because the browser closes the paragraph before it | A block element in a paragraph. |
| `<tag>` can't sit inside `<open>` because the browser closes `<open>` before it | Like `<li>` directly inside `<li>`. |
| `<tag>` can't sit inside `<heading>` because the browser closes the heading before it | A heading inside a heading. |
| `<tag>` can't sit inside `<svg>` because the browser moves it out | An HTML element inside `<svg>` or `<math>`. |
| `<tag>` must sit in `<parent>` because the browser drops or moves it elsewhere | Like `<td>` outside a table row. |

### Other messages

These don't have that ending:

| Message | Cause |
|---------|-------|
| `<tag>` only holds text because the browser reads its content as text | An element inside `<textarea>`, `<title>` and the like. |
| text can't sit directly in `<tag>` because the browser moves it out of the table | Text in `<table>` or `<tr>`. |
| `<child>` can't sit directly in `<tag>` because the browser would build another tree than the one rendered | A wrong child of a table element. |
| dynamic content inside `<tag>` isn't possible because it is not part of the DOM tree | Kotlin inside `<template>` or `<noscript>`. |
| `<textarea>` has no `value` attribute, write it as the content or bind it with `value={::name}` | `value` on a `<textarea>`. |
| `<select>` has no `value` attribute, set `selected` on its option | `value` on a `<select>`. |

## Bindings on elements

| Message | Cause |
|---------|-------|
| binding `name={...}` isn't possible because only `value`, `valueAsNumber`, `checked`, `group`, `open` are bound | Another attribute is bound. |
| binding `name={...}` isn't possible on `<tag>` because only text inputs, `<textarea>` and `<select>` bind `value` | The other bindings give their own reason, like only checkboxes bind `checked`, only radios and checkboxes bind `group`, only inputs of type number and range bind `valueAsNumber`, only `<details>` binds `open`. |
| binding `group={...}` needs a `value` attribute, which is what the group holds when this one is checked | A radio or checkbox without `value`. |
| a bound `value` and `@input` can't be on the same element because the binding already owns the `input` listener | The same with `checked` and `@change`, a `<select>` and `@change`, `open` and `@toggle`. |
| a bound `value` can't be on a `<textarea>` with content because the binding already sets it | Both a binding and content. |

## Head

| Message | Cause |
|---------|-------|
| `<head>` takes no attribute | An attribute on `<head>`. |
| `<head>` goes at the top level of the markup, outside every element and block, put a condition inside it | `<head>` is nested. |
| `<head>` only holds `<title>`, `<meta>`, `<link>`, `<script>`, `<style>`, `@if`, `@when`, `@for` and `@val` | Something else is inside. |
| `@await` isn't possible in `<head>`, put the `<head>` in a component inside the `@await` | An `@await` is inside. |
| `<tag>` isn't possible in `<head>`, which holds `<title>`, `<meta>`, `<link>`, `<script>`, `<style>` | Another element is inside. |
| `<base>` goes in `resources/index.html` because the browser reads it before the rest of the head | A `<base>` in a component. |
| `<meta charset>` goes in `resources/index.html` because the browser reads it before the rest of the head | A charset in a component. |
| `<tag>` only holds text in `<head>` | An element or a block inside a head element. |
| `name` isn't possible in `<head>`, whose elements only take attributes | An event or a directive on a head element. |
| `{*...}` isn't possible in `<head>`, whose elements only take attributes | A spread on a head element. |
| `name` has to be constant in `<head>` because it tells which elements replace one another | A computed `name`, `property` or the like. |
| a `<tag>` that changes isn't possible here yet because the browser finds the server element by its content, only `<title>`, `<meta>` with a `name`, `property` or `http-equiv` and the canonical `<link>` can hold Kotlin values | Another head element holds Kotlin values. |

## Style block

| Message | Cause |
|---------|-------|
| a `{` of the style block is never closed | A rule has no `}`. |
| stray `}` in the style block | A `}` closes nothing. |
| a string of the style block is never closed | A quote has no end. |
| a rule of the style block has no selector | `{ ... }` alone. |
| expected a rule, a declaration must sit inside a rule and read `property: value` | A declaration outside a rule, or without `:`. |
| only a `const val` can go in a selector, an at-rule or a property name because custom properties don't work there | A runtime value in those places. |
| only a `const val` can go in a CSS string because `var()` isn't read there | A runtime value in quotes. |
| only a `const val` can go in `<style global>` because it styles the whole page | A runtime value in a global block. |
| only a `const val` can go in `@name` because its descriptors don't read custom properties | A runtime value in the descriptors of `@font-face`, `@property`, `@counter-style` or `@font-palette-values`. |

## Static rendering

The page is rendered on the JVM, which has no browser.

| Message | Cause |
|---------|-------|
| this isn't possible during static rendering because it needs the browser API `name`, use it in `mount`, `effect` or an event handler | The markup reads a browser value. |
| a prop that uses the browser API `name` isn't possible yet because static rendering has no browser types | A prop type or default uses one. |
| a star import of a browser package isn't possible because the compiler can't tell which names it brings | Like `import web.html.*`. |

## Warnings

| Message | Cause |
|---------|-------|
| the prop `name` is never used | Nothing reads the prop. |
| `name` is never used | A declaration of the script nothing reads. |
| `name` is never assigned or bound, so it never changes and a `val` without `state` is enough | A `var` by `state` nothing writes. |
| `name` is computed once and doesn't follow `other`, write `val name by derived { ... }` | A plain `val` reads a reactive value. |
| `name` is only read in a callback that runs later, so the effect doesn't run again when it changes, read it in the effect: `val current = name` | An [effect](/docs/components/state#effects) doesn't follow what a callback reads. |
| `@name` only runs for a custom event, because browsers send none called `name` | Likely a typo. With `, write @other` when the name looks like `onclick`. |
| `<img>` without `alt` says nothing to screen readers and search engines, `alt=""` marks a decorative image | The image has no `alt`. |
| the selector `selector` matches no element of this component, `:global(...)` or a `<style global>` block reaches the elements it doesn't write | The selector of a [style block](/docs/components/styles) never applies, `:root`, `html` and `body` included. |

A warning that the name of a prop, a `val`, a `var` or a `fun` is never used reads the whole text of the file, so a name in a comment or a string counts, and
a destructuring or an `operator fun` is never reported.
