]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-objectstore-tool: Improve object spec error handling
authorDavid Zafman <dzafman@redhat.com>
Wed, 14 Oct 2015 20:12:17 +0000 (13:12 -0700)
committerDavid Zafman <dzafman@redhat.com>
Thu, 25 Feb 2016 20:50:26 +0000 (12:50 -0800)
Add test cases

Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit caf2d5970b0a3e3ce4ef941d1955b7821a0fc916)

Conflicts:
src/test/ceph_objectstore_tool.py (trivial)

src/tools/ceph_objectstore_tool.cc

index 8748c372c64c110c5ce735c8e8a7d2fab4144e42..961bfaa6a70d9dc77399b1593e87abe9abca7dd4 100644 (file)
@@ -3298,7 +3298,7 @@ int main(int argc, char **argv)
          if (lookup.size() != 1) {
            stringstream ss;
            if (lookup.size() == 0)
-             ss << "No object id '" << object << "' found";
+             ss << "No object id '" << object << "' found or invalid JSON specified";
            else
              ss << "Found " << lookup.size() << " objects with id '" << object
                 << "', please use a JSON spec from --op list instead";
@@ -3312,18 +3312,22 @@ int main(int argc, char **argv)
       } else {
        stringstream ss;
        if (pgidstr.length() == 0 && v.type() != json_spirit::array_type) {
-         ss << "object '" << object
-            << "' must be a JSON array but is of type "
-            << v.type() << " instead";
+         ss << "Without --pgid the object '" << object
+            << "' must be a JSON array";
          throw std::runtime_error(ss.str());
        }
        if (v.type() == json_spirit::array_type) {
          json_spirit::Array array = v.get_array();
+         if (array.size() != 2) {
+           ss << "Object '" << object
+              << "' must be a JSON array with 2 elements";
+           throw std::runtime_error(ss.str());
+         }
          vector<json_spirit::Value>::iterator i = array.begin();
+         //if (i == array.end() || i->type() != json_spirit::str_type) {
          if (i->type() != json_spirit::str_type) {
-           ss << "object '" << object
-              << "' must be a JSON array with the first element a string but "
-              << "found type " << v.type() << " instead";
+           ss << "Object '" << object
+              << "' must be a JSON array with the first element a string";
            throw std::runtime_error(ss.str());
          }
          string object_pgidstr = i->get_str();
@@ -3346,7 +3350,7 @@ int main(int argc, char **argv)
        try {
          ghobj.decode(v);
        } catch (std::runtime_error& e) {
-         ss << "Decode object json error: " << e.what();
+         ss << "Decode object JSON error: " << e.what();
          throw std::runtime_error(ss.str());
        }
         if ((uint64_t)pgid.pgid.m_pool != (uint64_t)ghobj.hobj.pool) {