Skip to content

Commit

Permalink
Add custom DPPM::Error exception
Browse files Browse the repository at this point in the history
  • Loading branch information
j8r committed Dec 4, 2019
1 parent 2d57d19 commit 5ddfe12
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ module DPPM::CLI
end
rescue ex
root_prefix.delete
raise Exception.new "DPPM installation failed, #{root_prefix.path} deleted", ex
raise Error.new "DPPM installation failed, #{root_prefix.path} deleted", ex
end
dppm_package.create_global_bin_symlinks(force: true) if Process.root?
Logger.info "DPPM installation complete", "you can now manage applications with the `#{Process.root? ? "dppm" : dppm_bin_path}` command"
Expand Down
3 changes: 3 additions & 0 deletions src/dppm.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module DPPM
class Error < Exception
end

extend self

def build_date : String
Expand Down
4 changes: 2 additions & 2 deletions src/http_helper.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "cossack"

# Method for redirections using the cossack http client
module HTTPHelper
module DPPM::HTTPHelper
extend self

def get_string(url)
Expand All @@ -12,7 +12,7 @@ module HTTPHelper
raise "Status code #{response.status}: " + url
end
rescue ex
raise Exception.new "Failed to get #{url.colorize.underline}", ex
raise Error.new "Failed to get #{url.colorize.underline}", ex
end

def get_file(url : String, path : String = File.basename(url))
Expand Down
4 changes: 2 additions & 2 deletions src/prefix/app.cr
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ struct DPPM::Prefix::App
begin
delete false { }
ensure
raise Exception.new "Add failed - application deleted: #{@path}", ex
raise Error.new "Add failed - application deleted: #{@path}", ex
end
ensure
self
Expand Down Expand Up @@ -812,7 +812,7 @@ struct DPPM::Prefix::App
begin
database?.try(&.check_connection) if !preserve_database
rescue ex
raise Exception.new "Either start the database or use the preseve database option", ex
raise Error.new "Either start the database or use the preseve database option", ex
end

# Checks
Expand Down
2 changes: 1 addition & 1 deletion src/prefix/pkg.cr
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class DPPM::Prefix::Pkg
begin
delete false { }
ensure
raise Exception.new "Build failed - package deleted: #{@path}", ex
raise Error.new "Build failed - package deleted: #{@path}", ex
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/prefix/program_data_task.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct DPPM::Prefix::ProgramData::Task
end
end
rescue ex
raise Exception.new "Error at line #{@line_number}", ex
raise Error.new "Error at line #{@line_number}", ex
end

# Assigns a value to a variable from a line string if it corresponds to an assignment.
Expand Down
3 changes: 3 additions & 0 deletions src/service.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ require "exec"
require "./service/*"

module Service
class Error < Exception
end

extend self

@@init : Systemd.class | OpenRC.class | Nil
Expand Down
2 changes: 1 addition & 1 deletion src/service/openrc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Service::OpenRC
output, error = Exec.new "/sbin/openrc", {"-V"}, &.wait
output.to_s.rpartition(' ')[-1].rpartition('.')[-1]
rescue ex
raise Exception.new "Can't retrieve the OpenRC version (#{output}#{error})", ex
raise Error.new "Can't retrieve the OpenRC version (#{output}#{error})", ex
end

def initialize(@name : String)
Expand Down
2 changes: 1 addition & 1 deletion src/service/openrc_config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Service::Config
end
line_number += 1
rescue ex
raise Exception.new "Parse error line at #{line_number}: #{full_line}", ex
raise Error.new "Parse error line at #{line_number}: #{full_line}", ex
end
service
end
Expand Down
2 changes: 1 addition & 1 deletion src/service/systemd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Service::Systemd
output, error = Exec.new "/bin/systemctl", {"--version"}, &.wait
output.to_s.lchop("systemd ").partition('\n')[0].partition(' ')[0].to_i
rescue ex
raise Exception.new "Can't retrieve the systemd version (#{output}#{error})", ex
raise Error.new "Can't retrieve the systemd version (#{output}#{error})", ex
end

def initialize(@name : String)
Expand Down
2 changes: 2 additions & 0 deletions src/web_site.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ require "./logger"
require "./web_site/*"

module WebSite
class Error < Exception
end
end
2 changes: 1 addition & 1 deletion src/web_site/caddy.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct WebSite::Caddy
end
line_number += 1
rescue ex
raise Exception.new "Caddyfile parsing error at line #{line_number} for #{raw_line}", ex
raise Error.new "Caddyfile parsing error at line #{line_number} for #{raw_line}", ex
end
end
end
Expand Down

0 comments on commit 5ddfe12

Please sign in to comment.