Errors   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 33
Duplicated Lines 0 %
Metric Value
dl 0
loc 33
rs 10
wmc 18

2 Methods

Rating   Name   Duplication   Size   Complexity  
C die() 0 20 15
A exception() 0 8 3
1
module MIDB
2
  module Interface
3
    # A view that outputs errors.
4
    class Errors
5
      # Handles fatal errors that will cause the application to abrort.
6
      # 
7
      # @param err [Symbol] The ID of the error that's to be reported.
8
      def self.die(err)
9
        errmsg =  case err
10
          when :noargs then "No command supplied. See `midb help`."
11
          when :server_already_started then "The server has already been started and is running."
12
          when :server_not_running then "The server isn't running."
13
          when :server_error then "Error while starting server."
14
          when :no_serves then "No files are being served. Try running `midb serve file.json`"
15
          when :syntax then "Syntax error. See `midb help`"
16
          when :file_404 then "File not found."
17
          when :not_json then "Specified file isn't JSON!"
18
          when :json_exists then "Specified file is already being served."
19
          when :json_not_exists then "The JSON file isn't being served."
20
          when :unsupported_engine then "The specified database engine isn't supported by midb."
21
          when :already_project then "This directory already contains a midb project."
22
          when :bootstrap then "midb hasn't been bootstraped in this folder. Run `midb bootstrap`."
23
          when :no_help then "No help available for this command. See a list of commands with `midb help`."
24
          else "Unknown error: #{err.to_s}"
25
        end
26
        abort("Fatal error: #{errmsg}")
27
      end
28
      def self.exception(exc, more="")
29
        excmsg = case exc
30
          when :database_error then "An error occurred when trying to connect to the database. #{more}"
31
          when :query_error then "An error occurred when trying to query the database. #{more}"
32
          else "Unknown exception: #{exc.to_s} #{more}"
33
        end
34
        puts "(exception)\t#{excmsg}"
35
      end
36
    end
37
  end
38
end