diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-10-25 20:41:57 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-12-16 20:39:53 +0000 |
commit | bfe3b02646e0b34562b28a3771f19b8a265f0856 (patch) | |
tree | 1f4cc8f53cc678db99be95db5f497019598258e6 /netfs/fuse | |
parent | Configuration types can be local with modern Slicer (diff) | |
download | netfs-bfe3b02646e0b34562b28a3771f19b8a265f0856.tar.bz2 netfs-bfe3b02646e0b34562b28a3771f19b8a265f0856.tar.xz netfs-bfe3b02646e0b34562b28a3771f19b8a265f0856.zip |
Improve exception usage around configuration lookups and simplify that code
Diffstat (limited to 'netfs/fuse')
-rw-r--r-- | netfs/fuse/Jamfile.jam | 5 | ||||
-rw-r--r-- | netfs/fuse/fuseApp.cpp | 8 | ||||
-rw-r--r-- | netfs/fuse/fuseConfig.ice | 7 | ||||
-rw-r--r-- | netfs/fuse/fuseConfigImpl.cpp | 10 |
4 files changed, 23 insertions, 7 deletions
diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index b17ca0b..9df3e89 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -5,8 +5,11 @@ lib Glacier2 : : <name>Glacier2 ; lib netfs-client-configuration : fuseConfig.ice + fuseConfigImpl.cpp : <slicer>yes + <library>../ice//netfs-api + <implicit-dependency>../ice//netfs-api <library>..//Ice <library>..//IceUtil <library>..//pthread @@ -21,7 +24,7 @@ lib netfs-client-configuration : lib netfs-client : netfs-client-configuration - [ glob *.cpp : netfs.cpp ] + [ glob *.cpp : fuseConfigImpl.cpp netfs.cpp ] : <define>_FILE_OFFSET_BITS=64 <implicit-dependency>../ice//netfs-api diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index a998f94..b980af8 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -6,6 +6,7 @@ #include <entCache.h> #include <slicer/slicer.h> #include <uriParse.h> +#include <safeMapFind.h> namespace AdHoc { template class Cache<struct stat, std::string>; @@ -82,12 +83,7 @@ NetFS::FuseApp::init(struct fuse_conn_info *) NetFS::Client::ResourcePtr NetFS::FuseApp::configureFromFile(const std::string & configPath, const std::string & resourceName) const { - auto fc = ReadConfiguration(configPath); - auto e = fc->Resources.find(resourceName); - if (e == fc->Resources.end()) { - throw std::runtime_error("No such resource: " + resourceName); - } - return e->second; + return AdHoc::safeMapLookup<Client::ResourceNotFound>(ReadConfiguration(configPath)->Resources, resourceName); } NetFS::Client::ResourcePtr diff --git a/netfs/fuse/fuseConfig.ice b/netfs/fuse/fuseConfig.ice index 91740fc..3e17017 100644 --- a/netfs/fuse/fuseConfig.ice +++ b/netfs/fuse/fuseConfig.ice @@ -1,3 +1,5 @@ +#include <exceptions.ice> + module NetFS { module Client { ["slicer:element:endpoint"] @@ -25,6 +27,11 @@ module NetFS { ["slicer:name:resources"] ResourceMap Resources; }; + + ["cpp:ice_print"] + exception ResourceNotFound extends ConfigError { + string resourceName; + }; }; }; diff --git a/netfs/fuse/fuseConfigImpl.cpp b/netfs/fuse/fuseConfigImpl.cpp new file mode 100644 index 0000000..9129bfc --- /dev/null +++ b/netfs/fuse/fuseConfigImpl.cpp @@ -0,0 +1,10 @@ +#include <fuseConfig.h> +#include <compileTimeFormatter.h> + +AdHocFormatter(ResourceNotFoundMsg, "No such resource: %?"); +void +NetFS::Client::ResourceNotFound::ice_print(std::ostream & s) const +{ + ResourceNotFoundMsg::write(s, resourceName); +} + |