InfluxElixir.StreamError exception (InfluxElixir v0.1.19)

Copy Markdown View Source

Raised while consuming a streaming query result when the request cannot produce rows.

Streaming query functions such as InfluxElixir.query_sql_stream/3 return an Enumerable.t(), so they cannot return an {:error, reason} tuple the way InfluxElixir.query_sql/3 does. Instead, error classes are surfaced by raising this exception at consumption time — the moment the stream is enumerated — so failures are never silently swallowed as "zero rows".

Kinds

  • :no_database — no database was resolved from opts or the connection
  • :http_status — the server responded with a non-success status; the :status and :body fields carry the response
  • :transport — a Finch/Mint transport error occurred; :reason carries it
  • :decode — a JSONL line could not be decoded as JSON; :reason carries the decode error
  • :unsupported — the operation is not supported by the connection's profile (raised by InfluxElixir.Client.Local for capability parity)

Example

try do
  conn
  |> InfluxElixir.query_sql_stream("SELECT * FROM cpu")
  |> Enum.to_list()
rescue
  e in InfluxElixir.StreamError ->
    Logger.error("stream failed: " <> Exception.message(e))
    {:error, e}
end

Summary

Functions

Builds an Enumerable.t() that raises this error the moment it is enumerated.

Types

kind()

@type kind() :: :no_database | :http_status | :transport | :decode | :unsupported

t()

@type t() :: %InfluxElixir.StreamError{
  __exception__: true,
  body: term(),
  kind: kind(),
  message: String.t(),
  reason: term(),
  status: non_neg_integer() | nil
}

Functions

stream(opts)

@spec stream(keyword()) :: Enumerable.t()

Builds an Enumerable.t() that raises this error the moment it is enumerated.

Streaming query functions return an Enumerable.t(), so a pre-request failure (no database, unsupported operation, an already-known error) cannot be returned as an {:error, reason} tuple. Wrapping it in this stream defers the raise to consumption time — matching the lazy semantics of a real streamed response — instead of yielding an empty list that looks like "zero rows".

opts are the same keyword options accepted by exception/1 (:kind, :status, :body, :reason).