How to use Foreman exceptions


friendly reminder for Foreman devs (and new info for Katello plugin
devs) follows.

We have defined two exceptions Foreman::Exception and
Foreman::WrappedException. Both are generic exceptions which are
i18n-friendly. Use the following style to properly format messages:

raise"Localized error message"))
raise"Localized error message: %s", substring_message))
raise"Localized error message %{a} and %{b}", {:a => a, :b => b}))
raise"Localized error message"), wrapped_exception)

It is very important to use N_ and not the simple _ (underscore)
function and to avoid using Ruby string interpolation, because those
exceptions prints out error codes which are generated from exception
class names and main (untranslated) messages. There is also a rake task
that goes through our codebase and generates list of all possible error
codes which we keep on the wiki page [[ErrorCodes]].

Feel free to use Foreman exceptions in plugins as well. Good example is
Foreman Discovery plugin.


··· -- Later,

Lukas “lzap” Zapletal
irc: lzap #theforeman