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

Holds the device's error reports until the extension sends them.

Runs from application start, not from the extension being attached. A crash
during boot is the one an operator most wants, and by the time NervesHub has
decided it wants error reports at all, it is long gone.

## The bound

A supervisor restart storm produces reports faster than they can be sent, and
a device the platform never attaches keeps crashing regardless. So this holds
a fixed number and drops the oldest past it, counting what went. The count
goes out as a report of its own ahead of the survivors, because a gap someone
can see beats a gap they cannot.

## Where the reports come from

A `:logger` handler, which runs in the process that crashed. Everything it
does is a `send/2` to this process: anything slower would charge the
application for the reporting, and anything that logs would recurse.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `count`

```elixir
@spec count() :: non_neg_integer()
```

How many reports are waiting, the drop notice included.

# `sent`

```elixir
@spec sent(non_neg_integer()) :: :ok
```

Forget the first `count` reports `take/1` returned, now that they have gone.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start collecting.

## Options

  * `:max_reports` - how many to hold. Defaults to
    `NervesHubLink.Extensions.ErrorReports.Config.max_reports/0`.

# `take`

```elixir
@spec take(pos_integer()) :: [NervesHubLink.Extensions.ErrorReports.Report.t()]
```

The next reports to send, oldest first, at most `max` of them.

Left where they are. Paired with `sent/1` rather than handing them over,
because a push can fail, and reports taken out of here and then not sent are
exactly what this exists to prevent.

---

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