Beispiel #1
0
void JsonRpcResponse::setError(const Error& error, const json::Value& clientInfo)
{
   // remove result
   response_.erase(kRpcResult);
   response_.erase(kRpcAsyncHandle);

   const boost::system::error_code& ec = error.code();
   
   if ( ec.category() == jsonRpcCategory() )
   {
      setError(ec);
   }
   else
   {
      // execution error
      json::Object jsonError ;
      copyErrorCodeToJsonError(errc::ExecutionError, &jsonError);
      
      // populate sub-error field with error details
      json::Object executionError;
      executionError["code"] = ec.value();
      std::string errorCategoryName = ec.category().name();
      executionError["category"] = errorCategoryName;
      std::string errorMessage = ec.message();
      executionError["message"] = errorMessage;
      jsonError["error"] = executionError;
      if (!clientInfo.is_null())
      {
         jsonError["client_info"] = clientInfo;
      }

      // set error
      setField(kRpcError, jsonError);
   }      
}
std::string pathFromProjectPath(json::Value projPathJson)
{
   // no project
   projects::ProjectContext& projectContext = projects::projectContext();
   if (!projectContext.hasProject())
      return std::string();

   // no proj path
   std::string projPath = !projPathJson.is_null() ? projPathJson.get_str() :
                                                    std::string();
   if (projPath.empty())
      return std::string();

   // interpret path relative to project directory
   FilePath filePath = projectContext.directory().childPath(projPath);
   if (filePath.exists())
      return module_context::createAliasedPath(filePath);
   else
      return std::string();
}
Beispiel #3
0
void JsonRpcResponse::setError(const boost::system::error_code& ec,
                               const json::Value& clientInfo)
{
   // remove result
   response_.erase(kRpcResult);
   response_.erase(kRpcAsyncHandle);

   // error from error code
   json::Object error ;
   copyErrorCodeToJsonError(ec, &error);

   // client info if provided
   if (!clientInfo.is_null())
   {
      error["client_info"] = clientInfo;
   }
   
   // sub-error is null
   error["error"] = json::Value();
   
   // set error
   setField(kRpcError, error);
}
Beispiel #4
0
SEXP create(const json::Value& value, Protect* pProtect)
{
   // call embedded create function based on type
   if (value.type() == json::StringType)
   {
      return create(value.get_str(), pProtect);
   }
   else if (value.type() == json::IntegerType)
   {
      return create(value.get_int(), pProtect);
   }
   else if (value.type() == json::RealType)
   {
      return create(value.get_real(), pProtect);
   }
   else if (value.type() == json::BooleanType)
   {
      return create(value.get_bool(), pProtect);
   }
   else if (value.type() == json::ArrayType)
   {
      return create(value.get_array(), pProtect);
   }
   else if (value.type() == json::ObjectType)
   {
      return create(value.get_obj(), pProtect);
   }
   else if (value.is_null())
   {
      return R_NilValue;
   }
   else
   {
      return R_NilValue;
   }
}