Module: Omnitest
- Includes:
- Core::Logger, Core::Logging
- Defined in:
- lib/omnitest/core/util.rb,
lib/omnitest/core.rb,
lib/omnitest/errors.rb,
lib/omnitest/core/cli.rb,
lib/omnitest/core/color.rb,
lib/omnitest/core/hashie.rb,
lib/omnitest/core/logger.rb,
lib/omnitest/core/logging.rb,
lib/omnitest/core/version.rb,
lib/omnitest/core/file_system.rb,
lib/omnitest/core/configurable.rb
Overview
Much of this code has been adapted from Fletcher Nichol (<[email protected]>) work on test-kitchen.
Defined Under Namespace
Modules: Core, Error, ErrorSource Classes: ActionFailed, ClientError, ExecutionError, StandardError, TransientFailure, UserError
Constant Summary collapse
- DEFAULT_LOG_LEVEL =
Default log level verbosity
:info
Class Attribute Summary collapse
-
.logger ⇒ Logger
The common Omnitest logger.
-
.mutex ⇒ Mutex
A common mutex for global coordination.
Class Method Summary collapse
- .basedir ⇒ Object
-
.env_log ⇒ Integer?
private
Determine the default log level from an environment variable, if it is set.
-
.handle_error(e) ⇒ Object
private
Handles an unexpected failure exception.
-
.handle_scenario_failure(e) ⇒ Object
(also: handle_validation_failure)
private
Handles an scenario failure exception.
-
.with_friendly_errors ⇒ Object
Yields to a code block in order to consistently emit a useful crash/error message and exit appropriately.
Methods included from Core::Logger
#log_level=, #logger, #new_logger, #stdout_logger
Class Attribute Details
.logger ⇒ Logger
Returns the common Omnitest logger.
29 30 31 |
# File 'lib/omnitest/core.rb', line 29 def logger @logger end |
.mutex ⇒ Mutex
Returns a common mutex for global coordination.
32 33 34 |
# File 'lib/omnitest/core.rb', line 32 def mutex @mutex end |
Class Method Details
.basedir ⇒ Object
34 35 36 |
# File 'lib/omnitest/core.rb', line 34 def basedir @basedir ||= Dir.pwd end |
.env_log ⇒ Integer?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine the default log level from an environment variable, if it is set.
47 48 49 50 51 |
# File 'lib/omnitest/core.rb', line 47 def env_log level = ENV['CROSSTEST_LOG'] && ENV['CROSSTEST_LOG'].downcase.to_sym level = Util.to_logger_level(level) unless level.nil? level end |
.handle_error(e) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handles an unexpected failure exception.
199 200 201 202 203 204 |
# File 'lib/omnitest/errors.rb', line 199 def handle_error(e) stderr_log(Error.formatted_exception(e)) stderr_log('Please see .omnitest/logs/omnitest.log for more details') # stderr_log("Also try running `omnitest diagnose --all` for configuration\n") file_log(:error, Error.formatted_trace(e)) end |
.handle_scenario_failure(e) ⇒ Object Also known as: handle_validation_failure
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handles an scenario failure exception.
185 186 187 188 189 190 |
# File 'lib/omnitest/errors.rb', line 185 def handle_scenario_failure(e) stderr_log(e..split(/\s{2,}/)) stderr_log(Error.formatted_exception(e.original)) file_log(:error, e..split(/\s{2,}/).first) debug_log(Error.formatted_trace(e)) end |
.with_friendly_errors ⇒ Object
Yields to a code block in order to consistently emit a useful crash/error message and exit appropriately. There are two primary failure conditions: an expected scenario failure, and any other unexpected failures.
Note This method may call ‘Kernel.exit` so may not return if the yielded code block raises an exception.
## Scenario Failure
This is an expected failure scenario which could happen if an scenario couldn’t be created, a Chef run didn’t successfully converge, a post-convergence test suite failed, etc. In other words, you can count on encountering these failures all the time–this is Omnitest’s worldview: crash early and often. In this case a cleanly formatted exception is written to ‘STDERR` and the exception message is written to the common Omnitest file logger.
## Unexpected Failure
All other forms of ‘Omnitest::Error` exceptions are considered unexpected or unplanned exceptions, typically from user configuration errors, driver or provisioner coding issues or bugs, or internal code issues. Given a stable release of Omnitest and a solid set of drivers and provisioners, the most likely cause of this is user configuration error originating in the `.omnitest.yaml` setup. For this reason, the exception is written to `STDERR`, a full formatted exception trace is written to the common Omnitest file logger, and a message is displayed on `STDERR` to the user informing them to check the log files and check their configuration with the `omnitest diagnose` subcommand.
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/omnitest/errors.rb', line 166 def with_friendly_errors yield rescue Omnitest::Skeptic::ScenarioFailure => e Omnitest.mutex.synchronize do handle_scenario_failure(e) end exit 10 rescue Omnitest::Error => e Omnitest.mutex.synchronize do handle_error(e) end exit 20 end |