Module: Factorix::CLI::Commands::CommandWrapper
- Defined in:
- lib/factorix/cli/commands/command_wrapper.rb
Overview
Module that wraps command execution to perform setup and error handling
This module is prepended to Base to ensure configuration loading, log level setup, and consistent error handling happen for every command execution.
Instance Method Summary collapse
-
#call(**options) ⇒ Object
Performs setup before command execution, then calls the command’s implementation Catches exceptions and displays user-friendly error messages.
Instance Method Details
#call(**options) ⇒ Object
Performs setup before command execution, then calls the command’s implementation Catches exceptions and displays user-friendly error messages
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/factorix/cli/commands/command_wrapper.rb', line 17 def call(**) @quiet = [:quiet] load_config!([:config_path]) log_level!([:log_level]) if [:log_level] super rescue Error => e # Expected errors (validation failures, missing dependencies, etc.) log = Container[:logger] log.warn(e.) log.debug(e) say "Error: #{e.}", prefix: :error unless @quiet raise # Re-raise for exe/factorix to handle exit code rescue => e # Unexpected errors (bugs, system failures, etc.) log = Container[:logger] log.error(e) say "Unexpected error: #{e.}", prefix: :error unless @quiet raise # Re-raise for exe/factorix to handle exit code end |