Exception: Suture::Error::ResultMismatch

Inherits:
StandardError
  • Object
show all
Defined in:
lib/suture/error/result_mismatch.rb

Instance Method Summary collapse

Constructor Details

#initialize(plan, new_result, old_result) ⇒ ResultMismatch

Returns a new instance of ResultMismatch.



3
4
5
6
7
# File 'lib/suture/error/result_mismatch.rb', line 3

def initialize(plan, new_result, old_result)
  @plan = plan
  @new_result = new_result
  @old_result = old_result
end

Instance Method Details

#messageObject



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/suture/error/result_mismatch.rb', line 9

def message
  <<-MSG.gsub(/^ {8}/,'')
    The results from the old & new code paths did not match for the seam
    #{@plan.name.inspect} and Suture is raising this error because the `:call_both`
    option is enabled, because both code paths are expected to return the
    same result.

    Arguments: ```
      #{@plan.args.inspect}
    ```
    The new code path #{@new_result.errored? ? "raised error" : "returned value"}: ```
      #{@new_result.value.inspect}
    ```
    The old code path #{@old_result.errored? ? "raised error" : "returned value"}: ```
      #{@old_result.value.inspect}
    ```

    Here's what we recommend you do next:

    1. Verify that this mismatch does not represent a missed requirement in
       the new code path. If it does, implement it!

    2. If either (or both) code path has a side effect that impacts the
       return value of the other, consider passing an `:after_old` and/or
       `:after_new` hook to clean up your application's state well enough to
       run both paths one-after-the-other safely.

    3. If the two return values above are sufficiently similar for the
       purpose of your application, consider writing your own custom
       comparator that relaxes the comparison (e.g. only checks equivalence
       of the attributes that matter). See the README for more info on custom
       comparators.

    4. If the new code path is working as desired (i.e. the old code path had
       a bug for this argument and you don't want to reimplement it just to
       make them perfectly in sync with one another), consider writing a
       one-off comparator for this seam that will ignore the affected range
       of arguments. See the README for more info on custom comparators.

    By default, Suture's :call_both mode will log a warning and raise an
    error when the results of each code path don't match. It is intended for
    use in any pre-production environment to "try out" the new code path
    before pushing it to production. If, for whatever reason, this error is
    too disruptive and logging is sufficient for monitoring results, you may
    disable this error by setting `:raise_on_result_mismatch` to false.
  MSG
end