Repository: chaostoolkit/chaostoolkit-lib

Issue:
Migrate FailedActivity exception to ActivityFailed

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ade7eac..f54b037 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@
 
 [Unreleased]: https://github.com/chaostoolkit/chaostoolkit-lib/compare/0.19.0...HEAD
 
+## Changed
+
+- renamed `FailedActivity` to a more active style: `ActivityFailed` [#17][17]
+
+[17]: https://github.com/chaostoolkit/chaostoolkit-lib/issues/17
+
 ## Added
 
 - support for loading experiments from a remote endpoint using the HTTP protocol
diff --git a/chaoslib/activity.py b/chaoslib/activity.py
index c1e7e0b..ceab369 100644
--- a/chaoslib/activity.py
+++ b/chaoslib/activity.py
@@ -13,7 +13,7 @@ from typing import Any, Iterator, List
 from logzero import logger
 
 from chaoslib.caching import lookup_activity
-from chaoslib.exceptions import FailedActivity, InvalidActivity, \
+from chaoslib.exceptions import ActivityFailed, InvalidActivity, \
     InvalidExperiment
 from chaoslib.provider.http import run_http_activity, validate_http_activity
 from chaoslib.provider.python import run_python_activity, \
@@ -140,7 +140,7 @@ def execute_activity(activity: Activity, configuration: Configuration,
     if ref:
         activity = lookup_activity(ref)
         if not activity:
-            raise FailedActivity(
+            raise ActivityFailed(
                 "could not find referenced activity '{r}'".format(r=ref))
 
     pauses = activity.get("pauses", {})
@@ -175,7 +175,7 @@ def execute_activity(activity: Activity, configuration: Configuration,
             logger.debug("  => succeeded with '{r}'".format(r=result))
         else:
             logger.debug("  => succeeded without any result value")
-    except FailedActivity as x:
+    except ActivityFailed as x:
         error_msg = str(x)
         run["status"] = "failed"
         run["output"] = result
@@ -201,7 +201,7 @@ def run_activity(activity: Activity, configuration: Configuration,
                  secrets: Secrets) -> Any:
     """
     Run the given activity and return its result. If the activity defines a
-    `timeout` this function raises :exc:`FailedActivity`.
+    `timeout` this function raises :exc:`ActivityFailed`.
 
     This function assumes the activity is valid as per
     `ensure_layer_activity_is_valid`. Please be careful not to call this
diff --git a/chaoslib/exceptions.py b/chaoslib/exceptions.py
index ef3d92c..a50043d 100644
--- a/chaoslib/exceptions.py
+++ b/chaoslib/exceptions.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 __all__ = ["ChaosException", "InvalidExperiment", "InvalidActivity",
-           "FailedActivity", "DiscoveryFailed", "InvalidSource"]
+           "ActivityFailed", "DiscoveryFailed", "InvalidSource"]
 
 
 class ChaosException(Exception):
@@ -16,10 +16,14 @@ class InvalidExperiment(ChaosException):
     pass
 
 
-class FailedActivity(ChaosException):
+class ActivityFailed(ChaosException):
     pass
 
 
+# please use ActivityFailed rather than the old name for this exception
+FailedActivity = ActivityFailed
+
+
 class DiscoveryFailed(ChaosException):
     pass
 
diff --git a/chaoslib/experiment.py b/chaoslib/experiment.py
index c3a0382..04f69b2 100644
--- a/chaoslib/experiment.py
+++ b/chaoslib/experiment.py
@@ -14,7 +14,7 @@ from chaoslib import __version__
 from chaoslib.activity import ensure_activity_is_valid, run_activities
 from chaoslib.caching import with_cache, lookup_activity
 from chaoslib.deprecation import warn_about_deprecated_features
-from chaoslib.exceptions import FailedActivity, InvalidActivity, \
+from chaoslib.exceptions import ActivityFailed, InvalidActivity, \
     InvalidExperiment
 from chaoslib.configuration import load_configuration
 from chaoslib.hypothesis import ensure_hypothesis_is_valid, \
@@ -191,11 +191,11 @@ def run_experiment(experiment: Experiment,
             journal["steady_states"]["before"] = state
             if state is not None and not state["steady_state_met"]:
                 p = state["probes"][-1]
-                raise FailedActivity(
+                raise ActivityFailed(
                     "Steady state probe '{p}' is not in the given tolerance "
                     "so failing this experiment".format(
                         p=p["activity"]["name"]))
-        except FailedActivity as a:
+        except ActivityFailed as a:
             journal["steady_states"]["before"] = state
             journal["status"] = "failed"
             logger.fatal(str(a))
@@ -215,11 +215,11 @@ def run_experiment(experiment: Experiment,
                     journal["steady_states"]["after"] = state
                     if state is not None and not state["steady_state_met"]:
                         p = state["probes"][-1]
-                        raise FailedActivity(
+                        raise ActivityFailed(
                             "Steady state probe '{p}' is not in the given "
                             "tolerance so failing this experiment".format(
                                 p=p["activity"]["name"]))
-                except FailedActivity as a:
+                except ActivityFailed as a:
                     journal["status"] = "failed"
                     logger.fatal(str(a))
     except (KeyboardInterrupt, SystemExit):
diff --git a/chaoslib/hypothesis.py b/chaoslib/hypothesis.py
index be58b45..2f1727f 100644
--- a/chaoslib/hypothesis.py
+++ b/chaoslib/hypothesis.py
@@ -16,7 +16,7 @@ from logzero import logger
 
 from chaoslib.activity import ensure_activity_is_valid, execute_activity, \
     run_activity
-from chaoslib.exceptions import FailedActivity, InvalidActivity, \
+from chaoslib.exceptions import ActivityFailed, InvalidActivity, \
     InvalidExperiment
 from chaoslib.types import Configuration, Experiment, Run, Secrets, Tolerance
 
diff --git a/chaoslib/provider/http.py b/chaoslib/provider/http.py
index 9131de3..b235925 100644
--- a/chaoslib/provider/http.py
+++ b/chaoslib/provider/http.py
@@ -9,7 +9,7 @@ from logzero import logger
 import requests
 
 from chaoslib import substitute
-from chaoslib.exceptions import FailedActivity, InvalidActivity
+from chaoslib.exceptions import ActivityFailed, InvalidActivity
 from chaoslib.types import Activity, Configuration, Secrets
 
 
@@ -25,7 +25,7 @@ def run_http_activity(activity: Activity, configuration: Configuration,
     A HTTP activity is a call to a HTTP endpoint and its result is returned as
     the raw result of this activity.
 
-    Raises :exc:`FailedActivity` when a timeout occurs for the request or when
+    Raises :exc:`ActivityFailed` when a timeout occurs for the request or when
     the endpoint returns a status in the 400 or 500 ranges.
 
     This should be considered as a private function.
@@ -81,10 +81,10 @@ def run_http_activity(activity: Activity, configuration: Configuration,
             "body": body
         }
     except requests.exceptions.ConnectionError as cex:
-        raise FailedActivity("failed to connect to {u}: {x}".format(
+        raise ActivityFailed("failed to connect to {u}: {x}".format(
             u=url, x=str(cex)))
     except requests.exceptions.Timeout:
-        raise FailedActivity("activity took too long to complete")
+        raise ActivityFailed("activity took too long to complete")
 
 
 def validate_http_activity(activity: Activity):
diff --git a/chaoslib/provider/process.py b/chaoslib/provider/process.py
index c981c3d..83faa95 100644
--- a/chaoslib/provider/process.py
+++ b/chaoslib/provider/process.py
@@ -10,7 +10,7 @@ from typing import Any
 from logzero import logger
 
 from chaoslib import substitute
-from chaoslib.exceptions import FailedActivity, InvalidActivity
+from chaoslib.exceptions import ActivityFailed, InvalidActivity
 from chaoslib.types import Activity, Configuration, Secrets
 
 
@@ -25,7 +25,7 @@ def run_process_activity(activity: Activity, configuration: Configuration,
     A process activity is an executable the current user is allowed to apply.
     The raw result of that command is returned as bytes of this activity.
 
-    Raises :exc:`FailedActivity` when a the process takes longer than the
+    Raises :exc:`ActivityFailed` when a the process takes longer than the
     timeout defined in the activity. There is no timeout by default so be
     careful when you do not explicitely provide one.
 
@@ -56,7 +56,7 @@ def run_process_activity(activity: Activity, configuration: Configuration,
             arguments, timeout=timeout, stdout=subprocess.PIPE,
             stderr=subprocess.PIPE, env=os.environ, shell=shell)
     except subprocess.TimeoutExpired:
-        raise FailedActivity("process activity took too long to complete")
+        raise ActivityFailed("process activity took too long to complete")
 
     return {
         "status": proc.returncode,
diff --git a/chaoslib/provider/python.py b/chaoslib/provider/python.py
index 61752a1..53eda80 100644
--- a/chaoslib/provider/python.py
+++ b/chaoslib/provider/python.py
@@ -10,7 +10,7 @@ from typing import Any
 from logzero import logger
 
 from chaoslib import substitute
-from chaoslib.exceptions import FailedActivity, InvalidActivity
+from chaoslib.exceptions import ActivityFailed, InvalidActivity
 from chaoslib.types import Activity, Configuration, Secrets
 
 
@@ -49,7 +49,7 @@ def run_python_activity(activity: Activity, configuration: Configuration,
     try:
         return func(**arguments)
     except Exception as x:
-        raise FailedActivity(
+        raise ActivityFailed(
             traceback.format_exception_only(
                 type(x), x)[0].strip()).with_traceback(
                     sys.exc_info()[2])


Test patch:
diff --git a/tests/test_experiment.py b/tests/test_experiment.py
index fa3e1c1..9eefb85 100644
--- a/tests/test_experiment.py
+++ b/tests/test_experiment.py
@@ -10,7 +10,7 @@ import pytest
 import requests_mock
 import yaml
 
-from chaoslib.exceptions import FailedActivity, InvalidActivity, \
+from chaoslib.exceptions import ActivityFailed, InvalidActivity, \
     InvalidExperiment
 from chaoslib.experiment import ensure_experiment_is_valid, load_experiment, \
     run_experiment, run_activities
diff --git a/tests/test_probe.py b/tests/test_probe.py
index 6266702..43ff4e4 100644
--- a/tests/test_probe.py
+++ b/tests/test_probe.py
@@ -6,7 +6,7 @@ import warnings
 import pytest
 import requests_mock
 
-from chaoslib.exceptions import FailedActivity, InvalidActivity
+from chaoslib.exceptions import ActivityFailed, InvalidActivity
 from chaoslib.activity import ensure_activity_is_valid, run_activity
 from chaoslib.provider import process as chaoslib_process
 from chaoslib.types import Probe
@@ -131,7 +131,7 @@ def test_run_process_probe_can_timeout():
     probe = probes.ProcProbe
     probe["provider"]["timeout"] = 0.0001
 
-    with pytest.raises(FailedActivity) as exc:
+    with pytest.raises(ActivityFailed) as exc:
         run_activity(
             probes.ProcProbe, config.EmptyConfig, 
             experiments.Secrets).decode("utf-8")
@@ -177,5 +177,5 @@ def test_run_http_probe_can_expect_failure():
 
         try:
             run_activity(probe, config.EmptyConfig, experiments.Secrets)
-        except FailedActivity:
+        except ActivityFailed:
             pytest.fail("activity should not have failed")