prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add field name of formatter failure to apply_formatters_to_dict
  * Version: 3.x & 4.x
  * Python: 2.7/3.4/3.5
  * OS: osx/linux/win
  
  
  ### What was wrong?
  
  When applying formatters to a dict, if one of the values fails, it's impossible to tell from the trace which one did.
  
  ### How can it be fixed?
  
  Catch ValueError exceptions in `apply_formatters_to_dict` and rethrow with the name of the field that failed.
  
  </issue>
  <code>
  [start of web3/utils/formatters.py]
  1 from collections import (
  2     Iterable,
  3     Mapping,
  4 )
  5 import sys
  6 
  7 from cytoolz.functoolz import (
  8     curry,
  9     compose,
  10 )
  11 
  12 from eth_utils import (
  13     is_string,
  14     to_list,
  15     to_dict,
  16 )
  17 
  18 from web3.utils.decorators import (
  19     reject_recursive_repeats,
  20 )
  21 
  22 
  23 def hex_to_integer(value):
  24     return int(value, 16)
  25 
  26 
  27 if sys.version_info.major == 2:
  28     def integer_to_hex(value):
  29         return hex(value).rstrip('L')
  30 else:
  31     integer_to_hex = hex
  32 
  33 
  34 @curry
  35 @to_list
  36 def apply_formatter_at_index(formatter, at_index, value):
  37     if at_index + 1 > len(value):
  38         raise IndexError(
  39             "Not enough values in iterable to apply formatter.  Got: {0}. "
  40             "Need: {1}".format(len(value), at_index)
  41         )
  42     for index, item in enumerate(value):
  43         if index == at_index:
  44             yield formatter(item)
  45         else:
  46             yield item
  47 
  48 
  49 def apply_formatters_to_args(*formatters):
  50     return compose(*(
  51         apply_formatter_at_index(formatter, index)
  52         for index, formatter
  53         in enumerate(formatters)
  54     ))
  55 
  56 
  57 @curry
  58 def apply_formatter_if(condition, formatter, value):
  59     if condition(value):
  60         return formatter(value)
  61     else:
  62         return value
  63 
  64 
  65 @curry
  66 @to_dict
  67 def apply_formatters_to_dict(formatters, value):
  68     for key, item in value.items():
  69         if key in formatters:
  70             yield key, formatters[key](item)
  71         else:
  72             yield key, item
  73 
  74 
  75 @curry
  76 @to_list
  77 def apply_formatter_to_array(formatter, value):
  78     for item in value:
  79         yield formatter(item)
  80 
  81 
  82 @curry
  83 def apply_one_of_formatters(formatter_condition_pairs, value):
  84     for formatter, condition in formatter_condition_pairs:
  85         if condition(value):
  86             return formatter(value)
  87     else:
  88         raise ValueError("The provided value did not satisfy any of the formatter conditions")
  89 
  90 
  91 def map_collection(func, collection):
  92     '''
  93     Apply func to each element of a collection, or value of a dictionary.
  94     If the value is not a collection, return it unmodified
  95     '''
  96     datatype = type(collection)
  97     if isinstance(collection, Mapping):
  98         return datatype((key, func(val)) for key, val in collection.items())
  99     if is_string(collection):
  100         return collection
  101     elif isinstance(collection, Iterable):
  102         return datatype(map(func, collection))
  103     else:
  104         return collection
  105 
  106 
  107 @reject_recursive_repeats
  108 def recursive_map(func, data):
  109     '''
  110     Apply func to data, and any collection items inside data (using map_collection).
  111     Define func so that it only applies to the type of value that you want it to apply to.
  112     '''
  113     def recurse(item):
  114         return recursive_map(func, item)
  115     items_mapped = map_collection(recurse, data)
  116     return func(items_mapped)
  117 
  118 
  119 def static_return(value):
  120     def inner(*args, **kwargs):
  121         return value
  122     return inner
  123 
  124 
  125 def static_result(value):
  126     def inner(*args, **kwargs):
  127         return {'result': value}
  128     return inner
  129 
  130 
  131 @curry
  132 @to_dict
  133 def apply_key_map(key_mappings, value):
  134     for key, item in value.items():
  135         if key in key_mappings:
  136             yield key_mappings[key], item
  137         else:
  138             yield key, item
  139
  [end of web3/utils/formatters.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/web3/utils/formatters.py b/web3/utils/formatters.py
  --- a/web3/utils/formatters.py
  +++ b/web3/utils/formatters.py
  @@ -67,7 +67,10 @@
   def apply_formatters_to_dict(formatters, value):
       for key, item in value.items():
           if key in formatters:
  -            yield key, formatters[key](item)
  +            try:
  +                yield key, formatters[key](item)
  +            except (TypeError, ValueError) as exc:
  +                raise type(exc)("Could not format value %r as field %r" % (item, key)) from exc
           else:
               yield key, item
  
verification_info: {"golden_diff": "diff --git a/web3/utils/formatters.py b/web3/utils/formatters.py\n--- a/web3/utils/formatters.py\n+++ b/web3/utils/formatters.py\n@@ -67,7 +67,10 @@\n def apply_formatters_to_dict(formatters, value):\n     for key, item in value.items():\n         if key in formatters:\n-            yield key, formatters[key](item)\n+            try:\n+                yield key, formatters[key](item)\n+            except (TypeError, ValueError) as exc:\n+                raise type(exc)(\"Could not format value %r as field %r\" % (item, key)) from exc\n         else:\n             yield key, item\n", "issue": "Add field name of formatter failure to apply_formatters_to_dict\n* Version: 3.x & 4.x\r\n* Python: 2.7/3.4/3.5\r\n* OS: osx/linux/win\r\n\r\n\r\n### What was wrong?\r\n\r\nWhen applying formatters to a dict, if one of the values fails, it's impossible to tell from the trace which one did.\r\n\r\n### How can it be fixed?\r\n\r\nCatch ValueError exceptions in `apply_formatters_to_dict` and rethrow with the name of the field that failed.\n", "before_files": [{"content": "from collections import (\n    Iterable,\n    Mapping,\n)\nimport sys\n\nfrom cytoolz.functoolz import (\n    curry,\n    compose,\n)\n\nfrom eth_utils import (\n    is_string,\n    to_list,\n    to_dict,\n)\n\nfrom web3.utils.decorators import (\n    reject_recursive_repeats,\n)\n\n\ndef hex_to_integer(value):\n    return int(value, 16)\n\n\nif sys.version_info.major == 2:\n    def integer_to_hex(value):\n        return hex(value).rstrip('L')\nelse:\n    integer_to_hex = hex\n\n\n@curry\n@to_list\ndef apply_formatter_at_index(formatter, at_index, value):\n    if at_index + 1 > len(value):\n        raise IndexError(\n            \"Not enough values in iterable to apply formatter.  Got: {0}. \"\n            \"Need: {1}\".format(len(value), at_index)\n        )\n    for index, item in enumerate(value):\n        if index == at_index:\n            yield formatter(item)\n        else:\n            yield item\n\n\ndef apply_formatters_to_args(*formatters):\n    return compose(*(\n        apply_formatter_at_index(formatter, index)\n        for index, formatter\n        in enumerate(formatters)\n    ))\n\n\n@curry\ndef apply_formatter_if(condition, formatter, value):\n    if condition(value):\n        return formatter(value)\n    else:\n        return value\n\n\n@curry\n@to_dict\ndef apply_formatters_to_dict(formatters, value):\n    for key, item in value.items():\n        if key in formatters:\n            yield key, formatters[key](item)\n        else:\n            yield key, item\n\n\n@curry\n@to_list\ndef apply_formatter_to_array(formatter, value):\n    for item in value:\n        yield formatter(item)\n\n\n@curry\ndef apply_one_of_formatters(formatter_condition_pairs, value):\n    for formatter, condition in formatter_condition_pairs:\n        if condition(value):\n            return formatter(value)\n    else:\n        raise ValueError(\"The provided value did not satisfy any of the formatter conditions\")\n\n\ndef map_collection(func, collection):\n    '''\n    Apply func to each element of a collection, or value of a dictionary.\n    If the value is not a collection, return it unmodified\n    '''\n    datatype = type(collection)\n    if isinstance(collection, Mapping):\n        return datatype((key, func(val)) for key, val in collection.items())\n    if is_string(collection):\n        return collection\n    elif isinstance(collection, Iterable):\n        return datatype(map(func, collection))\n    else:\n        return collection\n\n\n@reject_recursive_repeats\ndef recursive_map(func, data):\n    '''\n    Apply func to data, and any collection items inside data (using map_collection).\n    Define func so that it only applies to the type of value that you want it to apply to.\n    '''\n    def recurse(item):\n        return recursive_map(func, item)\n    items_mapped = map_collection(recurse, data)\n    return func(items_mapped)\n\n\ndef static_return(value):\n    def inner(*args, **kwargs):\n        return value\n    return inner\n\n\ndef static_result(value):\n    def inner(*args, **kwargs):\n        return {'result': value}\n    return inner\n\n\n@curry\n@to_dict\ndef apply_key_map(key_mappings, value):\n    for key, item in value.items():\n        if key in key_mappings:\n            yield key_mappings[key], item\n        else:\n            yield key, item\n", "path": "web3/utils/formatters.py"}]}