On 02/25/2014 11:02 PM, Aline Manera wrote:
On 02/25/2014 11:56 AM, Sheldon wrote:
On 02/25/2014 10:47 PM, Aline Manera wrote:

The exception instance was being used as the missing parameter what is
causing errors like below:
is KeyError?

dic = {"a": "a"}
In [124]: dic['b']
---------------------------------------------------------------------------
KeyError: 'b'


or TypeError?

TypeError: coercing to Unicode: need string or buffer, exceptions.KeyError found

As you can see the TypeError is caused by an KeyError
as I comment as follow:
except KeyError, item:
key is better than item?

why? it is a reference to the exception
But I am OK with both

sure. it is a reference. and agree it is not the scope of this patch.
item is just some confused.  Though it is OK.

For example:
In [168]: dog_owned_by = {'Peter': 'Furry', 'Sally': 'Fluffy'}

In [169]: dog_owned_by['NoExit']
KeyError: 'NoExit'

which are keys:
In [170]: dog_owned_by.keys()
Out[170]: ['Peter', 'Sally']

what are items:
In [171]: dog_owned_by.items()
Out[171]: [('Peter', 'Furry'), ('Sally', 'Fluffy')]

Anyway, this is not the scope of this patch



To fix use the string representation for the exception instance.

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
---
  src/kimchi/mockmodel.py            |    4 ++--
  src/kimchi/model/storagepools.py   |    2 +-
  src/kimchi/model/storagevolumes.py |    2 +-
  src/kimchi/root.py                 |    2 +-
  4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index b50bf31..b23a024 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -367,7 +367,7 @@ class MockModel(object):
                  pool.info['autostart'] = False
          except KeyError, item:
              raise MissingParameter("KCHPOOL0004E",
-                                   {'item': item, 'name': name})
+                                   {'item': str(item), 'name': name})
except KeyError, key:
key is right than item
here.


          if name in self._mock_storagepools or name in (ISO_POOL_NAME,):
              raise InvalidOperation("KCHPOOL0001E", {'name': name})







-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com>
IBM Linux Technology Center