error handling enhancements, recursive var subst
This commit is contained in:
parent
c3659eedfc
commit
763ae69982
8 changed files with 53 additions and 17 deletions
|
|
@ -13,7 +13,7 @@ namespace fc {
|
|||
class error_frame {
|
||||
public:
|
||||
error_frame( const fc::string& file, uint64_t line, const fc::string& method, const fc::string& desc, fc::value m );
|
||||
error_frame(){}
|
||||
error_frame():file("unknown-file"),line(0){}
|
||||
error_frame(const error_frame& );
|
||||
error_frame(error_frame&& );
|
||||
|
||||
|
|
@ -55,6 +55,7 @@ namespace fc {
|
|||
};
|
||||
|
||||
fc::string substitute( const fc::string& format, const fc::value& keys );
|
||||
fc::value recursive_substitute( const value& in, const fc::value& keys );
|
||||
|
||||
} // namespace fc
|
||||
|
||||
|
|
|
|||
|
|
@ -189,10 +189,8 @@ namespace fc {
|
|||
~key_val(){ }
|
||||
|
||||
key_val& operator=( key_val&& k ) {
|
||||
slog( "swap key");
|
||||
fc_swap( key, k.key );
|
||||
slog( "swap val");
|
||||
fc_swap( val, k.val );
|
||||
fc_swap( val, k.val );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -181,8 +181,7 @@ namespace fc {
|
|||
int idx = 0;
|
||||
for( auto i = a.fields.begin(); i != a.fields.end(); ++i ) {
|
||||
try {
|
||||
m_out.push_back(T());
|
||||
unpack( *i, m_out.back() );
|
||||
m_out.push_back( value_cast<T>( *i ) );
|
||||
} catch( fc::error_report& er ) {
|
||||
throw FC_REPORT_PUSH( er, "Error parsing array index ${index} to ${type}",
|
||||
fc::value().set("index", idx).set("type",fc::get_typename<T>::name()) );
|
||||
|
|
@ -234,9 +233,7 @@ namespace fc {
|
|||
template<typename Member>
|
||||
void operator()( Member& m ) {
|
||||
try {
|
||||
//m = value_cast<Member>(_val[idx]);
|
||||
unpack( _val[idx], m );
|
||||
// m = value_cast<Member>(_val[idx]);
|
||||
m = value_cast<Member>(_val[idx]);
|
||||
} catch ( fc::error_report& er ) {
|
||||
throw FC_REPORT_PUSH( er, "Error parsing tuple element ${index}", fc::value().set("index",idx) );
|
||||
}
|
||||
|
|
@ -332,9 +329,6 @@ namespace fc {
|
|||
}
|
||||
template<typename T>
|
||||
T value::cast()const {
|
||||
T tmp;
|
||||
unpack(*this,tmp);
|
||||
return tmp;
|
||||
// return unpackvalue_cast<T>(*this);
|
||||
return value_cast<T>(*this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,28 @@ fc::string substitute( const fc::string& format, const fc::value& keys ) {
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs variable substitution on all strings in keys or values of 'in' with
|
||||
* values from keys.
|
||||
*/
|
||||
fc::value recursive_substitute( const value& in, const fc::value& keys ) {
|
||||
fc::value out;
|
||||
if( in.is_string() ) {
|
||||
return fc::substitute( in.cast<string>(), keys );
|
||||
}
|
||||
else if( in.is_object() ) {
|
||||
for( auto itr = in.begin(); itr != in.end(); ++itr ) {
|
||||
out[fc::substitute(itr->key, keys)] = recursive_substitute( itr->val, keys );
|
||||
}
|
||||
return out;
|
||||
}
|
||||
else if( in.is_array() ) {
|
||||
for( size_t i = 0; i < in.size(); ++i ) {
|
||||
out.push_back( recursive_substitute( in[i], keys ) );
|
||||
}
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
fc::string error_report::to_string()const {
|
||||
fc::stringstream ss;
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ namespace fc {
|
|||
void remove_all( const path& p ) { boost::filesystem::remove_all(p); }
|
||||
void copy( const path& f, const path& t ) {
|
||||
try {
|
||||
boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) );
|
||||
boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) );
|
||||
} catch ( boost::system::system_error& e ) {
|
||||
FC_THROW_REPORT( "Copy from ${srcfile} to ${dstfile} failed because ${reason}",
|
||||
fc::value().set("srcfile",f).set("dstfile",t).set("reason",e.what() ) );
|
||||
|
|
@ -147,9 +147,29 @@ namespace fc {
|
|||
fc::value().set("srcfile",f).set("dstfile",t).set("inner", fc::except_str() ) );
|
||||
}
|
||||
}
|
||||
void create_hard_link( const path& f, const path& t ) { boost::filesystem::create_hard_link( f, t ); }
|
||||
bool remove( const path& f ) { return boost::filesystem::remove( f ); }
|
||||
fc::path canonical( const fc::path& p ) { return boost::filesystem::canonical(p); }
|
||||
void create_hard_link( const path& f, const path& t ) {
|
||||
try {
|
||||
boost::filesystem::create_hard_link( f, t );
|
||||
} catch ( ... ) {
|
||||
FC_THROW_REPORT( "Unable to create hard link from '${from}' to '${to}'",
|
||||
fc::value().set( "from", f )
|
||||
.set("to",t).set("exception", fc::except_str() ) );
|
||||
}
|
||||
}
|
||||
bool remove( const path& f ) {
|
||||
try {
|
||||
boost::filesystem::remove( f );
|
||||
} catch ( ... ) {
|
||||
FC_THROW_REPORT( "Unable to remove '${path}'", fc::value().set( "path", f ).set("exception", fc::except_str() ) );
|
||||
}
|
||||
}
|
||||
fc::path canonical( const fc::path& p ) {
|
||||
try {
|
||||
return boost::filesystem::canonical(p);
|
||||
} catch ( ... ) {
|
||||
FC_THROW_REPORT( "Unable to resolve path '${path}'", fc::value().set( "path", p ).set("exception", fc::except_str() ) );
|
||||
}
|
||||
}
|
||||
fc::path absolute( const fc::path& p ) { return boost::filesystem::absolute(p); }
|
||||
path unique_path() { return boost::filesystem::unique_path(); }
|
||||
path temp_directory_path() { return boost::filesystem::temp_directory_path(); }
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ namespace fc { namespace json {
|
|||
while( !in.eof() ) {
|
||||
// std::cerr<<"\n**line size: "<<line.size()<<"\n\n";
|
||||
// slog( "line size: '%d'", line.size() );
|
||||
// slog( "%s", line.c_str() );
|
||||
try {
|
||||
fc::value v= fc::json::from_string( line );
|
||||
self.handle_message(v);
|
||||
|
|
|
|||
BIN
vendor/libssh2-1.4.2/libssh2_debug.a
vendored
BIN
vendor/libssh2-1.4.2/libssh2_debug.a
vendored
Binary file not shown.
BIN
vendor/sigar/libsigar_debug.a
vendored
BIN
vendor/sigar/libsigar_debug.a
vendored
Binary file not shown.
Loading…
Reference in a new issue