From 50aa053124c1508bff02d3a7022a3bf7a47f214f Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Wed, 7 Oct 2020 09:48:25 +0200 Subject: [PATCH] Do not throw an exception when object package is not found in init() --- .../libraries/ArmarXObjects/ObjectFinder.cpp | 23 ++++++++++++++++++- .../libraries/ArmarXObjects/ObjectFinder.h | 7 +++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp index a02b6bd10..089bd030b 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp +++ b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp @@ -25,7 +25,7 @@ namespace armarx if (packageDataDir.empty()) { ARMARX_WARNING << "Could not find package '" << packageName << "'."; - throw LocalException() << "Could not find package '" << packageName << "'."; + // throw LocalException() << "Could not find package '" << packageName << "'."; } else { @@ -38,6 +38,10 @@ namespace armarx std::optional<ObjectInfo> ObjectFinder::findObject(const std::string& dataset, const std::string& name) const { init(); + if (!_ready()) + { + return std::nullopt; + } if (!dataset.empty()) { return ObjectInfo(packageName, packageDataDir, dataset, name); @@ -88,6 +92,10 @@ namespace armarx std::vector<ObjectFinder::path> ObjectFinder::getDatasetDirectories() const { init(); + if (!_ready()) + { + return {}; + } const bool local = false; std::vector<path> dirs = simox::fs::list_directory(_rootDirAbs(), local); std::vector<path> datasetDirs; @@ -104,6 +112,10 @@ namespace armarx std::vector<ObjectInfo> ObjectFinder::findAllObjects(bool checkPaths) const { init(); + if (!_ready()) + { + return {}; + } const bool local = true; std::vector<ObjectInfo> objects; for (const path& datasetDir : simox::fs::list_directory(_rootDirAbs(), local)) @@ -135,6 +147,10 @@ namespace armarx std::vector<ObjectInfo> ObjectFinder::findAllObjectsOfDataset(const std::string& dataset, bool checkPaths) const { init(); + if (!_ready()) + { + return {}; + } path datasetDir = _rootDirAbs() / dataset; if (!fs::is_directory(datasetDir)) { @@ -169,5 +185,10 @@ namespace armarx return packageName; } + bool ObjectFinder::_ready() const + { + return !packageDataDir.empty(); + } + } diff --git a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h index 3c56afba7..411edb339 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h +++ b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h @@ -44,13 +44,18 @@ namespace armarx path _rootDirAbs() const; path _rootDirRel() const; + bool _ready() const; + private: /// Name of package containing the object models (ArmarXObjects by default). mutable std::string packageName; - /// Absolute path to data directory (e.g. "/.../repos/ArmarXObjects/data"). + /** + * @brief Absolute path to data directory (e.g. "/.../repos/ArmarXObjects/data"). + * Empty if package could not be found. + */ mutable path packageDataDir; }; -- GitLab