Class: PuppetGenerator::Middleware::HandleErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_generator/middleware/handle_errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ HandleErrors

Returns a new instance of HandleErrors.



4
5
6
# File 'lib/puppet_generator/middleware/handle_errors.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(t) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/puppet_generator/middleware/handle_errors.rb', line 8

def call(t)
  @task = t

  PuppetGenerator.logger.debug(self.class.name){ "Waiting for errors to occure. ;-)" }

  begin
    @app.call(task)
  rescue PuppetGenerator::Exceptions::InvalidSource
    exit_with_error :invalid_source, source: task.meta[:source], command: task.meta[:command] 
  rescue PuppetGenerator::Exceptions::InvalidOutputChannel
    exit_with_error :invalid_output_channel
  rescue PuppetGenerator::Exceptions::EmptySource
    exit_with_error :empty_source, source: task.meta[:source]
  rescue PuppetGenerator::Exceptions::UnknownImportFilter
    exit_with_error :unknown_import_filter, requested_import_filter: task.meta[:requested_import_filter], 
                                            available_import_filter: Models::ImportFilter.all_names_as_string
  rescue PuppetGenerator::Exceptions::InvalidYamlInput
    exit_with_error :invalid_yaml_input
  rescue PuppetGenerator::Exceptions::InvalidPasswdInput
    exit_with_error :invalid_passwd_input
  rescue PuppetGenerator::Exceptions::UnknownAction
    exit_with_error :unknown_action, requested_actions: task.meta[:requested_actions], 
                                     available_actions: Models::Action.all_names_as_string
  rescue PuppetGenerator::Exceptions::FilesystemError
    exit_with_error :filesystem_error, fs_object: task.meta[:source]
  rescue PuppetGenerator::Exceptions::WrongTemplateChosen
    exit_with_error :wrong_template_chosen, command: task.meta[:command], tags: task.meta[:template_tagged_with].to_a.join(", "), destination: task.meta[:destination] 
  rescue PuppetGenerator::Exceptions::InternalError => e
    exit_with_error :internal_error, exception_message: e.message
  rescue Interrupt
    exit_with_error :interrupt
  end
end