Sheetshow.Error exception (Sheetshow v0.1.0)

Copy Markdown View Source

The error behind every {:error, _} Sheetshow returns and every ! variant raises.

reason is an atom for your code to match on, message is for humans, and details carries whatever helps: the offending cell, the HTTP status, the ids that moved.

iex> error = Sheetshow.Error.new(:invalid_style, "unknown style key :bolt", key: :bolt)
iex> error.reason
:invalid_style
iex> error.details
%{key: :bolt}
iex> Exception.message(error)
"unknown style key :bolt"

The reasons

Cells and ranges:

reasonmeaning
:invalid_a1a string that does not parse as A1 notation
:invalid_rangea range a read cannot use: one that names no sheet
:invalid_cell, :invalid_value, :invalid_stylea cell a plan refuses to write, with the cell in details
:missing_sheeta cell that names no sheet and was given none

Plans and sheets:

reasonmeaning
:unknown_sheetan op for a sheet the spreadsheet has not got
:duplicate_sheetan AddSheet for a sheet that is already there
:unsupportedthe backend cannot promise what was asked of it; see Sheetshow.Backend

Schemas, logs and tables:

reasonmeaning
:invalid_schemanot a keyword list of known types
:invalid_record, :unknown_columna record a schema refuses to write: wrong type, or a key with no column
:casta cell that would not read as its column's type; a flag on the row, or the error under strict: true
:missing_header, :missing_columna tab whose header is not there, or lacks a column the schema needs
:missing_idan event with no id, which cannot be written
:unknown_id, :duplicate_ida change naming an id the snapshot cannot place, or one two rows share
:conflicting_changestwo changes to one id in one plan
:movedthe rows above a log cursor, or a table's header, have changed since the read: read again

Credentials and tokens:

reasonmeaning
:invalid_credentialsa key file or authorized_user JSON that does not parse
:no_credentials, :no_tokena workbook built without them, asked to do what needs them
:no_refresh_tokena user account nobody has consented for yet
:auththe token endpoint or the consent screen refused
:state_mismatchan OAuth answer to a request that was not yours
:invalid_token_responsea token endpoint answer with no token in it

The network and files:

reasonmeaning
:transportno answer at all: DNS, TCP, TLS or a timeout, in details.reason
:httpany other non-2xx, with details.status and the server's message
:rate_limitedGoogle's per-minute quota, with details.retry_after in seconds when it named one
:not_founda file or URL that is not there; Sheetshow.Workbook.xlsx/2 with create: true makes one
:conflicta store refused a write because the file changed since it was read
:iothe local filesystem refused, with the POSIX reason in details.posix
:invalid_zip, :invalid_xlsx, :unknown_entrya file that is not a workbook Sheetshow can read

Summary

Functions

Builds an error. details may be a map or a keyword list.

Types

reason()

@type reason() ::
  :invalid_a1
  | :invalid_range
  | :invalid_cell
  | :invalid_value
  | :invalid_style
  | :missing_sheet
  | :unknown_sheet
  | :duplicate_sheet
  | :unsupported
  | :invalid_schema
  | :invalid_record
  | :unknown_column
  | :cast
  | :missing_header
  | :missing_column
  | :missing_id
  | :unknown_id
  | :duplicate_id
  | :conflicting_changes
  | :moved
  | :invalid_credentials
  | :no_credentials
  | :no_token
  | :no_refresh_token
  | :auth
  | :state_mismatch
  | :invalid_token_response
  | :transport
  | :http
  | :rate_limited
  | :not_found
  | :conflict
  | :io
  | :invalid_zip
  | :invalid_xlsx
  | :unknown_entry

t()

@type t() :: %Sheetshow.Error{
  __exception__: term(),
  details: map(),
  message: String.t(),
  reason: reason()
}

Functions

new(reason, message, details \\ %{})

@spec new(reason(), String.t(), map() | keyword()) :: t()

Builds an error. details may be a map or a keyword list.