Class: MIDB::Interface::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/midb/errors_view.rb

Overview

A view that outputs errors.

Class Method Summary collapse

Class Method Details

.die(err) ⇒ Object

Handles fatal errors that will cause the application to abrort.

Parameters:

  • err (Symbol)

    The ID of the error that’s to be reported.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/midb/errors_view.rb', line 8

def self.die(err)
  errmsg =  case err
    when :noargs then "No command supplied. See `midb help`."
    when :server_already_started then "The server has already been started and is running."
    when :server_not_running then "The server isn't running."
    when :server_error then "Error while starting server."
    when :no_serves then "No files are being served. Try running `midb serve file.json`"
    when :syntax then "Syntax error. See `midb help`"
    when :file_404 then "File not found."
    when :not_json then "Specified file isn't JSON!"
    when :json_exists then "Specified file is already being served."
    when :json_not_exists then "The JSON file isn't being served."
    when :unsupported_engine then "The specified database engine isn't supported by midb."
    when :already_project then "This directory already contains a midb project."
    when :bootstrap then "midb hasn't been bootstraped in this folder. Run `midb bootstrap`."
    when :no_help then "No help available for this command. See a list of commands with `midb help`."
    else "Unknown error: #{err.to_s}"
  end
  abort("Fatal error: #{errmsg}")
end

.exception(exc, more = "") ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/midb/errors_view.rb', line 28

def self.exception(exc, more="")
  excmsg = case exc
    when :database_error then "An error occurred when trying to connect to the database. #{more}"
    when :query_error then "An error occurred when trying to query the database. #{more}"
    else "Unknown exception: #{exc.to_s} #{more}"
  end
  puts "(exception)\t#{excmsg}"
end