improve type change error messages
This commit is contained in:
@@ -14,6 +14,9 @@ Library of common type definitions. ::
|
||||
|
||||
ntscalar
|
||||
|
||||
.. note::
|
||||
The nt::* factories are expensive. Avoid repeated use with `pvxs::Value::cloneEmpty`.
|
||||
|
||||
.. _time_t:
|
||||
|
||||
time_t
|
||||
|
||||
+1
-1
@@ -218,7 +218,7 @@ struct ServerMonitorControl : public server::MonitorControlOp
|
||||
Guard G(mon->lock);
|
||||
|
||||
if(val && mon->type && mon->type.get()!=Value::Helper::desc(val))
|
||||
throw std::logic_error("Type change not allowed in post()");
|
||||
throw std::logic_error("Type change not allowed in post(). Recommend pvxs::Value::cloneEmpty()");
|
||||
|
||||
if((mon->queue.size() < mon->limit) || force || !val) {
|
||||
mon->queue.push_back(std::move(val));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user