# V6010 non_std_effect_in_main

URL: /docs/errors/V6010
Markdown: /docs/errors/V6010.md

> main's effect row may contain only std effects, because only they have host root handlers (design §9).

An error from the `capability` phase. `sakura explain V6010` prints this explanation offline.

`main`'s effect row may contain only std effects, because only they have host root handlers
(design §9). Handle user effects inside `main` with `with`.

Wrong:

```sakura
pub fn main() -> Unit ! {Db} { let _ = Db.count() }
```

Fixed:

```sakura
pub fn main() -> Unit ! {Console} {
  with empty_db() { Console.print("{Db.count()} rows") }
}
```

## Wrong program [#wrong-program]

[`compiler/tests/ui/V6010_non_std_effect_in_main.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V6010_non_std_effect_in_main.sakura), which the compiler's ui suite runs through `sakura check`:

```sakura
effect Db {
  fn count() -> Int
}

pub fn main() -> Unit ! {Db} { let _ = Db.count() }
```

`sakura check --json` reports this record (pretty-printed; `$DIR` is the fixture's directory):

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:5373cf157bc6101f",
  "code": "V6010",
  "severity": "error",
  "phase": "capability",
  "message": "only std effects may appear in `main`'s row, because only they have host handlers; handle `Db` (from `main/V6010_non_std_effect_in_main`) inside `main` with `with` and remove it from the row",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V6010_non_std_effect_in_main::main",
  "spans": [
    {
      "uri": "file://$DIR/V6010_non_std_effect_in_main.sakura",
      "content_hash": "sha256:078c14d559d336cea5c09610d1a85ad083cbda818318ac750afcd2aceb5d8c23",
      "start_byte": 94,
      "end_byte": 96,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V6010",
  "fixes": []
}
```

## Fixed program [#fixed-program]

[`compiler/tests/ui/V6010_non_std_effect_in_main.fixed.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V6010_non_std_effect_in_main.fixed.sakura), which `sakura check` accepts with no diagnostics:

```sakura
effect Db {
  fn count() -> Int
}

fn empty_db() -> Handler<Db> {
  handler Db {
    fn count() { 0 }
  }
}

pub fn main() -> Unit ! {Console} { with empty_db() { Console.print("{Db.count()} rows") } }
```
