improve type change error messages

This commit is contained in:
Michael Davidsaver
2020-05-19 10:03:02 -07:00
parent 2d075cbc1c
commit 027e590fba
3 changed files with 14 additions and 1 deletions
+10
View File
@@ -17,6 +17,7 @@
#include <pvxs/server.h>
#include "utilpvt.h"
#include "dataimpl.h"
typedef epicsGuard<epicsMutex> Guard;
typedef epicsGuardRelease<epicsMutex> UnGuard;
@@ -298,6 +299,8 @@ void SharedPV::open(const Value& initial)
{
if(!impl)
throw std::logic_error("Empty SharedPV");
else if(!initial || initial.type()!=TypeCode::Struct)
throw std::logic_error("Must specify non-empty initial Struct");
decltype (impl->pending) pending;
decltype (impl->mpending) mpending;
@@ -382,9 +385,16 @@ void SharedPV::post(Value&& val)
{
if(!impl)
throw std::logic_error("Empty SharedPV");
else if(!val)
throw std::logic_error("Can't post() empty Value");
Guard G(impl->lock);
if(!impl->current)
throw std::logic_error("Must open() before post()ing");
else if(Value::Helper::desc(impl->current)!=Value::Helper::desc(val))
throw std::logic_error("post() requires the exact type of open(). Recommend pvxs::Value::cloneEmpty()");
impl->current.assign(val);
for(auto& sub : impl->subscribers) {