From d13023b32a990241a4a0ebb7fb2dab5391c003e3 Mon Sep 17 00:00:00 2001
From: zhiyuan_cai <luckyvega.g@gmail.com>
Date: Wed, 11 Feb 2015 10:35:10 +0800
Subject: [PATCH] Fix error msg in sort_items

Include direction users pass in the error msg to help users know
which part of the argument is troublesome.

Change-Id: I796a85fbf40f6ddf544fb52a61f967e1914abdcc
Closes-Bug: #1420732
---
 openstackclient/common/utils.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index 01a40e742b..d1c7970a26 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -200,8 +200,14 @@ def sort_items(items, sort_str):
         reverse = False
         if ':' in sort_key:
             sort_key, direction = sort_key.split(':', 1)
+            if not sort_key:
+                msg = "empty string is not a valid sort key"
+                raise exceptions.CommandError(msg)
             if direction not in ['asc', 'desc']:
-                msg = "Specify sort direction by asc or desc"
+                if not direction:
+                    direction = "empty string"
+                msg = ("%s is not a valid sort direction for sort key %s, "
+                       "use asc or desc instead" % (direction, sort_key))
                 raise exceptions.CommandError(msg)
             if direction == 'desc':
                 reverse = True