Commit 27700ef8 authored by Victor Poughon's avatar Victor Poughon

Merge branch '1850-imagefilereader' into 'develop'

Fix ImageFileReader error message & add back otb::Logger::BuildFormattedEntry

Closes #1850

See merge request !400
parents b154b9b4 412cb686
......@@ -69,6 +69,9 @@ public:
/** Set the flag m_LogSetupInfoDone to true */
void LogSetupInformationDone();
// Overwrite this to provide custom formatting of log entries
std::string BuildFormattedEntry(itk::Logger::PriorityLevelType, std::string const&) override;
protected:
Logger();
virtual ~Logger() override = default;
......
......@@ -26,6 +26,9 @@
#include "gdal.h"
#include "itkMultiThreader.h"
#include <type_traits>
#include <cassert>
namespace otb
{
......@@ -117,4 +120,21 @@ void Logger::LogSetupInformationDone()
m_LogSetupInfoDone = true;
}
std::string Logger::BuildFormattedEntry(itk::Logger::PriorityLevelType level, std::string const& content)
{
static const std::string levelString[] = {"(MUSTFLUSH)", "(FATAL)", "(CRITICAL)", "(WARNING)", "(INFO)", "(DEBUG)", "(NOTSET)"};
assert(level <= std::extent<decltype(levelString)>::value);
if (strcmp(this->GetName(), "") == 0)
{
return itksys::SystemTools::GetCurrentDateTime("%Y-%m-%d %H:%M:%S") + " " + levelString[level] + ": " + content;
}
else
{
return itksys::SystemTools::GetCurrentDateTime("%Y-%m-%d %H:%M:%S") + " " + levelString[level] + " " + this->GetName() + ": " + content;
}
}
} // namespace otb
......@@ -601,11 +601,11 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
// Test if the file exists.
if (!itksys::SystemTools::FileExists(fileToCheck))
{
throw otb::ImageFileReaderException (__FILE__, __LINE__, "The file does not exist.", fileToCheck);
throw otb::ImageFileReaderException (__FILE__, __LINE__, std::string("Cannot open image ") + fileToCheck + std::string(". The file does not exist."), fileToCheck);
}
else
{
throw otb::ImageFileReaderException(__FILE__, __LINE__, "Probably unsupported format or incorrect filename extension.", this->m_FileName);
throw otb::ImageFileReaderException(__FILE__, __LINE__, std::string("Cannot open image ") + this->m_FileName + std::string(". Probably unsupported format or incorrect filename extension."), this->m_FileName);
}
}
}
......
......@@ -300,56 +300,36 @@ int main(int ac, char* av[])
return -1;
}
else
{
{
otb::Logger::Instance()->LogSetupInformation();
MainFuncPointer f = j->second;
int result;
try
{
{
// Invoke the test's "main" function.
result = (*f)(ac - 1, av + 1);
if (result != EXIT_SUCCESS )
{
if (result != EXIT_SUCCESS)
{
std::cout << "-> Test EXIT FAILURE (" << result << ")." << std::endl;
itkGenericExceptionMacro(<< "Function returns EXIT_FAILURE (not from regression, failure inside the test)");
}
}
catch (const otb::ImageFileReaderException& e)
{
std::cerr << "otbTestMain '" << testToRun << "': ImageFileReaderException:" << std::endl;
std::cerr << e.GetFile() << ":" << e.GetLine() << ":" << std::endl;
std::cerr << std::string("Cannot open image ") + e.m_Filename + std::string(". ") + e.GetDescription() << std::endl;
result = EXIT_FAILURE;
}
catch (const itk::ExceptionObject& e)
{
std::cerr << "otbTestMain '" << testToRun << "': ITK Exception thrown:" << std::endl;
std::cerr << e.GetFile() << ":" << e.GetLine() << ":" << std::endl;
std::cerr << e.GetDescription() << std::endl;
result = EXIT_FAILURE;
}
catch (const std::bad_alloc& err)
{
std::cerr << "otbTestMain '" << testToRun << "': Exception bad_alloc thrown: " << std::endl;
std::cerr << (char*) err.what() << std::endl;
result = EXIT_FAILURE;
}
catch (const std::exception& e)
{
std::cerr << "otbTestMain '" << testToRun << "': std::exception thrown:" << std::endl;
std::cerr << e.what() << std::endl;
{
std::cerr << "otbTestMain '" << testToRun << "': exception caught:" << std::endl;
std::cerr << e.what() << std::endl;
result = EXIT_FAILURE;
}
}
catch (...)
{
std::cerr << "otbTestMain '" << testToRun << "': Unknown exception thrown !" << std::endl;
{
std::cerr << "otbTestMain '" << testToRun << "': unknown exception caught!" << std::endl;
result = EXIT_FAILURE;
}
}
if (result != EXIT_SUCCESS )
{
return -1;
}
if (result != EXIT_SUCCESS)
{
return -1;
}
result = EXIT_SUCCESS;
......
......@@ -179,7 +179,7 @@ bool CommandLineLauncher::ExecuteAndWriteOutput()
{
m_Application->GetLogger()->Debug("Caught otb::ImageFileReaderException during application execution:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
m_Application->GetLogger()->Fatal(string("Cannot open image ") + err.m_Filename + string(". ") + err.GetDescription() + string("\n"));
m_Application->GetLogger()->Fatal(err.GetDescription() + string("\n"));
return false;
}
catch(itk::ExceptionObject& err)
......
......@@ -73,27 +73,26 @@ QtWidgetModel
{
m_Application->GetLogger()->Debug("Caught otb::ApplicationException during application update:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
emit ExceptionRaised( err.what() );
emit ExceptionRaised(err.what());
}
catch(otb::ImageFileReaderException& err)
{
m_Application->GetLogger()->Debug("Caught otb::ImageFileReaderException during application update:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
string message( string("Cannot open image ") + err.m_Filename + string(". ") + err.GetDescription() );
m_Application->GetLogger()->Fatal( message + string("\n"));
emit ExceptionRaised( message.c_str() );
m_Application->GetLogger()->Fatal(err.GetDescription() + string("\n"));
emit ExceptionRaised(err.what());
}
catch(itk::ExceptionObject& err)
{
m_Application->GetLogger()->Debug("Caught itk::ExceptionObject during application update:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
m_Application->GetLogger()->Fatal(string(err.GetDescription()) + "\n");
emit ExceptionRaised( err.GetDescription() );
emit ExceptionRaised(err.GetDescription());
}
catch(std::exception& err)
{
m_Application->GetLogger()->Fatal(string("Caught std::exception during application update: ") + err.what() + "\n");
emit ExceptionRaised( err.what() );
emit ExceptionRaised(err.what());
}
catch(...)
{
......@@ -305,8 +304,8 @@ AppliThread
{
m_Application->GetLogger()->Debug("Caught otb::ImageFileReaderException during application execution:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
m_Application->GetLogger()->Fatal(string("Cannot open image ") + err.m_Filename + string(". ") + err.GetDescription() + string("\n"));
emit ExceptionRaised( err.what() );
m_Application->GetLogger()->Fatal(err.GetDescription() + string("\n"));
emit ExceptionRaised(err.what());
}
catch(itk::ProcessAborted& /*err*/)
{
......
......@@ -31,7 +31,7 @@
$action
} catch(otb::ImageFileReaderException& err) {
std::ostringstream oss;
oss << "Cannot open image " << err.m_Filename + ". " + err.GetDescription();
oss << err.GetDescription();
SWIG_exception( SWIG_RuntimeError, oss.str().c_str() );
} catch( itk::ExceptionObject &ex ) {
std::ostringstream oss;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment