# `NervesHubLink.Extensions.ErrorReports`
[🔗](https://github.com/nerves-hub/nerves_hub_link/blob/v2.14.0/lib/nerves_hub_link/extensions/error_reports.ex#L5)

The Error Reports Extension, version 0.1.0.

Sends the device's exceptions, exits and explicit error reports to NervesHub,
where they are grouped into issues you can resolve or mute. One direction
only: nothing is ever sent back.

Off by default. To turn it on, name it in `extension_modules` along with the
other extensions you want, since the list replaces the defaults rather than
adding to them:

    config :nerves_hub_link,
      extension_modules: [
        NervesHubLink.Extensions.Geo,
        NervesHubLink.Extensions.Health,
        NervesHubLink.Extensions.NetworkIdentity,
        NervesHubLink.Extensions.ErrorReports
      ]

Like every extension, it sends nothing until NervesHub asks the device to
attach it, and NervesHub only asks if the product has the extension enabled.

## What gets reported

Anything the runtime attaches a `crash_reason` to: a process dying with an
exception, an exit or a throw, a GenServer termination, a failed task. See
`NervesHubLink.Extensions.ErrorReports.Handler` for why that is the signal
rather than the log level.

Application code can also report an error it caught and handled, with context
the stacktrace cannot know:

    try do
      charge(order)
    rescue
      error -> NervesHubLink.report_error(error, __STACKTRACE__, group: "payments")
    end

## Why it batches

A crash loop is the case this is built for. NervesHub limits how often a
device may send rather than how much it may say, so a message carrying
twenty-five reports costs exactly what one carrying a single report costs.
Sending one report per message would lose most of a restart storm and keep an
arbitrary sample of it.

Reports collect in `NervesHubLink.Extensions.ErrorReports.Collector` from
application start, so a crash during boot, or while the device is offline, is
still there to send once there is a connection.

## Configuration

    config :nerves_hub_link,
      error_reports: [
        max_reports: 100,
        interval_seconds: 60,
        context: {MyApp.Telemetry, :error_context, []}
      ]

See `NervesHubLink.Extensions.ErrorReports.Config`, and in particular
`NervesHubLink.Extensions.ErrorReports.Config.context/0` for attaching device
state such as reboot count or free memory to every report.

# `flush`

```elixir
@spec flush() :: :ok
```

Send whatever has collected, without waiting for the next flush.

## Examples

    iex> NervesHubLink.Extensions.ErrorReports.flush()
    :ok

---

*Consult [api-reference.md](api-reference.md) for complete listing*
