Skip to content

Commit f5370a7

Browse files
committed
Error message improvement
1 parent f07f1c8 commit f5370a7

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/Modules/Legacy/Matlab/Interface/InterfaceWithMatlab.cc

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -887,12 +887,12 @@ bool InterfaceWithMatlabImpl::open_matlab_engine()
887887

888888
if (!engOpen || !engClose || !engSetVisible || !engEvalString || !engOutputBuffer)
889889
{
890-
if (!engOpen) module_->error(std::string("Cannot find engOpen"));
891-
if (!engClose) module_->error(std::string("Cannot find engClose"));
892-
if (!engSetVisible) module_->error(std::string("Cannot find engSetVisible"));
893-
if (!engEvalString) module_->error(std::string("Cannot find engEvalString"));
894-
if (!engOutputBuffer) module_->error(std::string("Cannot find engOutputBuffer"));
895-
module_->error(std::string("Could not open matlab engine functions from matlab library"));
890+
if (!engOpen) module_->error("Cannot find engOpen");
891+
if (!engClose) module_->error("Cannot find engClose");
892+
if (!engSetVisible) module_->error("Cannot find engSetVisible");
893+
if (!engEvalString) module_->error("Cannot find engEvalString");
894+
if (!engOutputBuffer) module_->error("Cannot find engOutputBuffer");
895+
module_->error("Could not open matlab engine functions from matlab library");
896896
return false;
897897
}
898898
}
@@ -915,8 +915,7 @@ bool InterfaceWithMatlabImpl::open_matlab_engine()
915915

916916
if (!engine_)
917917
{
918-
module_->error(std::string("InterfaceWithMatlab: Could not open matlab engine"));
919-
module_->error(std::string("InterfaceWithMatlab: Check remote address information, or leave all fields except 'session' blank to connect to local matlab engine"));
918+
module_->error("InterfaceWithMatlab: Could not open matlab engine. Check remote address information, or leave all fields except 'session' blank to connect to local matlab engine.");
920919
return false;
921920
}
922921

@@ -926,24 +925,24 @@ bool InterfaceWithMatlabImpl::open_matlab_engine()
926925

927926

928927
file_transfer_.reset(new FileTransferClient());
929-
if (!(file_transfer_->open(address, "matlabenginefiletransfer", sessionnum, passwd)))
928+
if (!file_transfer_->open(address, "matlabenginefiletransfer", sessionnum, passwd))
930929
{
931930
std::string err;
932931
#ifndef USE_MATLAB_ENGINE_LIBRARY
933932
err = matlab_engine_->geterror();
934933
matlab_engine_->close();
935-
matlab_engine_ = 0;
934+
matlab_engine_.reset();
936935
#else
937936
engClose(engine_);
938937
engine_ = 0;
939938
#endif
940-
std::cout << "ERROR" << file_transfer_->geterror() << std::endl;
941-
module_->error(std::string("InterfaceWithMatlab: Could not open matlab engine file transfer service (error=") + err + std::string(")"));
942-
module_->error(std::string("InterfaceWithMatlab: Make sure the matlab engine file transfer service has not been disabled in [MATLAB_DIRECTPRY]/services/matlabengine.rc"));
943-
module_->error(std::string("InterfaceWithMatlab: Press the 'Edit Local Config of Matlab Engine' to change the configuration"));
944-
module_->error(std::string("InterfaceWithMatlab: Check remote address information, or leave all fields except 'session' blank to connect to local matlab engine"));
945-
946-
file_transfer_ = 0;
939+
std::ostringstream ostr;
940+
ostr << "InterfaceWithMatlab: Could not open matlab engine file transfer service (error=" << err << ")" <<
941+
".\n Make sure the matlab engine file transfer service has not been disabled in [MATLAB_DIRECTPRY]/services/matlabengine.rc.\n" <<
942+
" Press the 'Edit Local Config of Matlab Engine' to change the configuration." <<
943+
" Check remote address information, or leave all fields except 'session' blank to connect to local matlab engine.";
944+
module_->error(ostr.str());
945+
file_transfer_.reset();
947946
return(false);
948947
}
949948

@@ -960,14 +959,14 @@ bool InterfaceWithMatlabImpl::open_matlab_engine()
960959
{
961960
#ifndef USE_MATLAB_ENGINE_LIBRARY
962961
matlab_engine_->close();
963-
matlab_engine_ = 0;
962+
matlab_engine_.reset();
964963
#else
965964
engClose(engine_);
966965
engine_ = 0;
967966
#endif
968-
module_->error(std::string("InterfaceWithMatlab: Could not create remote temporary directory"));
967+
module_->error("InterfaceWithMatlab: Could not create remote temporary directory.");
969968
file_transfer_->close();
970-
file_transfer_ = 0;
969+
file_transfer_.reset();
971970
return(false);
972971
}
973972
file_transfer_->set_local_dir(temp_directory_);
@@ -991,9 +990,11 @@ bool InterfaceWithMatlabImpl::open_matlab_engine()
991990
{
992991
matlab_engine_->close();
993992
file_transfer_->close();
994-
module_->error(std::string("InterfaceWithMatlab: Could not get answer from matlab engine (error=") + matlab_engine_->geterror() + std::string(")"));
995-
module_->error(std::string("InterfaceWithMatlab: This is an internal communication error, make sure that the portnumber is correct"));
996-
module_->error(std::string("InterfaceWithMatlab: If address information is correct, this most probably points to a bug in the SCIRun software"));
993+
std::ostringstream ostr;
994+
ostr << "Could not get answer from matlab engine (error=" << matlab_engine_->geterror() << ").\n " <<
995+
" This is an internal communication error, make sure that the portnumber is correct. \n" <<
996+
" If address information is correct, this most probably points to a bug in the SCIRun software.";
997+
module_->error(ostr.str());
997998

998999
matlab_engine_.reset();
9991000
file_transfer_.reset();
@@ -1007,11 +1008,13 @@ bool InterfaceWithMatlabImpl::open_matlab_engine()
10071008
matlab_engine_->close();
10081009
file_transfer_->close();
10091010

1010-
module_->error(std::string("InterfaceWithMatlab: InterfaceWithMatlab engine returned an error (error=") + packet->getstring() + std::string(")"));
1011-
module_->error(std::string("InterfaceWithMatlab: Please check whether '[MATLAB_DIRECTORY]/services/matlabengine.rc' has been setup properly"));
1012-
module_->error(std::string("InterfaceWithMatlab: Press the 'Edit Local Config of Matlab Engine' to change the configuration"));
1013-
module_->error(std::string("InterfaceWithMatlab: Edit the 'startmatlab=' line to start matlab properly"));
1014-
module_->error(std::string("InterfaceWithMatlab: If you running matlab remotely, this file must be edited on the machine running matlab"));
1011+
std::ostringstream ostr;
1012+
ostr << "InterfaceWithMatlab engine returned an error (error=" << packet->getstring() << ")" <<
1013+
"\n Please check whether '[MATLAB_DIRECTORY]/services/matlabengine.rc' has been setup properly." <<
1014+
"\n Press the 'Edit Local Config of Matlab Engine' to change the configuration." <<
1015+
"\n Edit the 'startmatlab=' line to start matlab properly. " <<
1016+
"\n If you running matlab remotely, this file must be edited on the machine running matlab.";
1017+
module_->error(ostr.str());
10151018

10161019
matlab_engine_.reset();
10171020
file_transfer_.reset();

0 commit comments

Comments
 (0)