Module: MelissaData::Errors

Defined in:
lib/melissadata/errors.rb

Overview

This module contains all of the internal errors in MelissaData’s core. These errors are expected errors and as such don’t typically represent bugs in MelissaData itself. These are meant as a way to detect errors and display them in a user-friendly way.

# Defining a new Error

To define a new error, inherit from MelissaDataError, which lets MelissaData know that this is an expected error, and also gives you some helpers for providing exit codes and error messages. An example is shown below, then it is explained:

class MyError < MelissaData::Errors::MelissaDataError
  error_key "my_error"
end

This creates an error with an I18n error key of “my_error.” MelissaDataError uses I18n to look up error messages, in the “melissadata.errors” namespace. So in the above, the error message would be the translation of “melissadata.errors.my_error”

If you don’t want to use I18n, you can override the #initialize method and set your own error message.

# Raising an Error

To raise an error, it is nothing special, just raise it like any normal exception:

raise MyError.new

Eventually this exception will bubble out to the ‘melissadata` binary which will show a nice error message. And if it is raised in the middle of a middleware sequence, then Action::Warden will catch it and begin the recovery process prior to exiting.

Defined Under Namespace

Classes: DiscNotFound, MelissaDataError