Composer.Error (composer v0.2.0)

Copy Markdown View Source

Formats the {:error, reason} values returned by composer's modules, and the warnings returned by Composer.Resolver.warnings/1.

Library functions return errors as data; Mix tasks pass the reason to message/1 and raise with Mix.raise/1. Every message says what is wrong and how to fix it.

Summary

Types

What an error is about, for placing it in a file (see anchor/1).

Functions

Returns what an error is about: not a position, but the thing to look for, which Composer.Lint turns into a file and a range.

Returns a human-readable message for an error reason.

Returns a human-readable message for a resolver warning.

Types

anchor()

@type anchor() ::
  {:ref, String.t() | nil, String.t()}
  | {:entry, String.t(), term()}
  | {:recipe_key, String.t(), atom() | {:if, atom()}}
  | {:alias, String.t(), atom()}
  | {:recipe, String.t()}
  | {:recipe_name, Path.t(), String.t() | atom()}
  | {:recipe_named, String.t(), String.t()}
  | {:cycle, [String.t()]}
  | {:install, String.t(), [{String.t() | nil, String.t()}]}
  | {:file, Path.t()}
  | {:file, Path.t(), pos_integer() | nil}
  | {:step, String.t()}
  | {:step, String.t(), {:template | :requires | :test, String.t()}}
  | nil

What an error is about, for placing it in a file (see anchor/1).

Functions

anchor(arg1)

@spec anchor(term()) :: anchor() | :unknown

Returns what an error is about: not a position, but the thing to look for, which Composer.Lint turns into a file and a range.

  • {:ref, origin, written} - a reference as written in recipe origin (nil when the error does not say; the recipe being checked is meant)
  • {:entry, recipe_ref, entry} - a whole step entry
  • {:recipe_key, recipe_ref, key} - one of a recipe's keys; {:if, flag} for an if: flag
  • {:alias, recipe_ref, name} - a cookbook alias
  • {:recipe, recipe_ref} - a recipe's name key
  • {:recipe_name, path, name} - every name key name in a group file
  • {:recipe_named, cookbook, name} - a recipe named name in any group of cookbook
  • {:cycle, chain} - the include that closes a cycle
  • {:install, package, [{origin, label}]} - the installs of a package
  • {:file, path} / {:file, path, line} - a file, or one of its lines
  • {:step, step_ref} / {:step, step_ref, detail} - a step's source, at its use Composer.Step, a template/1 path or a requires ref
  • nil - nothing to point at

A new error kind gets a message/1 clause and an anchor/1 clause; a test checks that every message/1 tag has one.

message(other)

@spec message(term()) :: String.t()

Returns a human-readable message for an error reason.

warning(arg)

@spec warning({atom(), term(), term()} | {atom(), term(), term(), term()}) ::
  String.t()

Returns a human-readable message for a resolver warning.