Skip to content

Commit ff31545

Browse files
authored
Merge pull request #52 from DannyBen/add/custom-exceptions
Change exception classes
2 parents 77d22cd + 3ce16ac commit ff31545

File tree

10 files changed

+15
-10
lines changed

10 files changed

+15
-10
lines changed

lib/completely.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'lp'
44
end
55

6+
require 'completely/exceptions'
67
require 'completely/pattern'
78
require 'completely/completions'
89
require 'completely/tester'

lib/completely/commands/init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Init < Base
1212
environment_config_path
1313

1414
def run
15-
raise "File already exists: #{config_path}" if File.exist? config_path
15+
raise Error, "File already exists: #{config_path}" if File.exist? config_path
1616

1717
File.write config_path, sample
1818
say "Saved m`#{config_path}`"

lib/completely/commands/install.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def run
2626
end
2727

2828
success = installer.install force: args['--force']
29-
raise "Failed running command:\nnb`#{installer.command_string}`" unless success
29+
raise InstallError, "Failed running command:\nnb`#{installer.command_string}`" unless success
3030

3131
say "Saved m`#{installer.target_path}`"
3232
say 'You may need to restart your session to test it'

lib/completely/exceptions.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Completely
2+
class Error < StandardError; end
3+
class InstallError < Error; end
4+
end

lib/completely/installer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ def target_path
3030

3131
def install(force: false)
3232
unless completions_path
33-
raise 'Cannot determine system completions directory'
33+
raise InstallError, 'Cannot determine system completions directory'
3434
end
3535

3636
unless script_exist?
37-
raise "Cannot find script: m`#{script_path}`"
37+
raise InstallError, "Cannot find script: m`#{script_path}`"
3838
end
3939

4040
if target_exist? && !force
41-
raise "File exists: m`#{target_path}`"
41+
raise InstallError, "File exists: m`#{target_path}`"
4242
end
4343

4444
system(*command)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<RuntimeError: File already exists: completely.yaml>
1+
#<Completely::Error: File already exists: completely.yaml>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#<RuntimeError: Failed running command:
1+
#<Completely::InstallError: Failed running command:
22
nb`sudo cp source target`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<RuntimeError: Cannot determine system completions directory>
1+
#<Completely::InstallError: Cannot determine system completions directory>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<RuntimeError: Cannot find script: m`tmp/missing-file`>
1+
#<Completely::InstallError: Cannot find script: m`tmp/missing-file`>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<RuntimeError: File exists: m`spec/fixtures/existing-file.txt`>
1+
#<Completely::InstallError: File exists: m`spec/fixtures/existing-file.txt`>

0 commit comments

Comments
 (0)