Skip to content

Commit

Permalink
remove dependency on member variable which is being accessed by multi…
Browse files Browse the repository at this point in the history
…ple threads (race condition)
  • Loading branch information
cbielow committed Aug 14, 2023
1 parent ef37a65 commit 331436c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
6 changes: 0 additions & 6 deletions src/openms/include/OpenMS/FORMAT/HANDLERS/XMLHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,6 @@ namespace OpenMS
/// Writes the contents to a stream.
virtual void writeTo(std::ostream & /*os*/);

/// Returns the last error description
String errorString();

/// handler which support partial loading, implement this method
virtual LOADDETAIL getLoadDetail() const;

Expand Down Expand Up @@ -469,9 +466,6 @@ namespace OpenMS
void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids) const;

protected:
/// Error message of the last error
mutable String error_message_;

/// File name
String file_;

Expand Down
10 changes: 5 additions & 5 deletions src/openms/source/FORMAT/HANDLERS/MzMLHandlerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ namespace OpenMS::Internal

void MzMLHandlerHelper::warning(int mode, const String & msg, UInt line, UInt column)
{
String error_message_;
String error_message;
if (mode == 0)
{
error_message_ = String("While loading '") + "': " + msg;
error_message = String("While loading '") + "': " + msg;
}
else if (mode == 1)
{
error_message_ = String("While storing '") + "': " + msg;
error_message = String("While storing '") + "': " + msg;
}
if (line != 0 || column != 0)
{
error_message_ += String("( in line ") + line + " column " + column + ")";
error_message += String("( in line ") + line + " column " + column + ")";
}
OPENMS_LOG_WARN << error_message_ << std::endl;
OPENMS_LOG_WARN << error_message << std::endl;
}

String MzMLHandlerHelper::getCompressionTerm_(const PeakFileOptions& opt, MSNumpressCoder::NumpressConfig np, const String& indent, bool use_numpress)
Expand Down
38 changes: 18 additions & 20 deletions src/openms/source/FORMAT/HANDLERS/XMLHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,70 +104,73 @@ namespace OpenMS::Internal

void XMLHandler::fatalError(ActionMode mode, const String & msg, UInt line, UInt column) const
{
String error_message;
if (mode == LOAD)
{
error_message_ = String("While loading '") + file_ + "': " + msg;
error_message = String("While loading '") + file_ + "': " + msg;
// test if file has the wrong extension and is therefore passed to the wrong parser
// only makes sense if we are loading/parsing a file
FileTypes::Type ft_name = FileHandler::getTypeByFileName(file_);
FileTypes::Type ft_content = FileHandler::getTypeByContent(file_);
if (ft_name != ft_content)
{
error_message_ += String("\nProbable cause: The file suffix (") + FileTypes::typeToName(ft_name)
error_message += String("\nProbable cause: The file suffix (") + FileTypes::typeToName(ft_name)
+ ") does not match the file content (" + FileTypes::typeToName(ft_content) + "). "
+ "Rename the file to fix this.";
}
}
else if (mode == STORE)
{
error_message_ = String("While storing '") + file_ + "': " + msg;
error_message = String("While storing '") + file_ + "': " + msg;
}
if (line != 0 || column != 0)
{
error_message_ += String("( in line ") + line + " column " + column + ")";
error_message += String("( in line ") + line + " column " + column + ")";
}

OPENMS_LOG_FATAL_ERROR << error_message_ << std::endl;
throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, file_, error_message_);
OPENMS_LOG_FATAL_ERROR << error_message << std::endl;
throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, file_, error_message);
}

void XMLHandler::error(ActionMode mode, const String & msg, UInt line, UInt column) const
{
String error_message;
if (mode == LOAD)
{
error_message_ = String("Non-fatal error while loading '") + file_ + "': " + msg;
error_message = String("Non-fatal error while loading '") + file_ + "': " + msg;
}
else if (mode == STORE)
{
error_message_ = String("Non-fatal error while storing '") + file_ + "': " + msg;
error_message = String("Non-fatal error while storing '") + file_ + "': " + msg;
}
if (line != 0 || column != 0)
{
error_message_ += String("( in line ") + line + " column " + column + ")";
error_message += String("( in line ") + line + " column " + column + ")";
}
OPENMS_LOG_ERROR << error_message_ << std::endl;
OPENMS_LOG_ERROR << error_message << std::endl;
}

void XMLHandler::warning(ActionMode mode, const String & msg, UInt line, UInt column) const
{
String error_message;
if (mode == LOAD)
{
error_message_ = String("While loading '") + file_ + "': " + msg;
error_message = String("While loading '") + file_ + "': " + msg;
}
else if (mode == STORE)
{
error_message_ = String("While storing '") + file_ + "': " + msg;
error_message = String("While storing '") + file_ + "': " + msg;
}
if (line != 0 || column != 0)
{
error_message_ += String("( in line ") + line + " column " + column + ")";
error_message += String("( in line ") + line + " column " + column + ")";
}

// warn only in Debug mode but suppress warnings in release mode (more happy users)
#ifdef OPENMS_ASSERTIONS
OPENMS_LOG_WARN << error_message_ << std::endl;
OPENMS_LOG_WARN << error_message << std::endl;
#else
OPENMS_LOG_DEBUG << error_message_ << std::endl;
OPENMS_LOG_DEBUG << error_message << std::endl;
#endif

}
Expand All @@ -188,11 +191,6 @@ namespace OpenMS::Internal
{
}

String XMLHandler::errorString()
{
return error_message_;
}

SignedSize XMLHandler::cvStringToEnum_(const Size section, const String & term, const char * message, const SignedSize result_on_error)
{
OPENMS_PRECONDITION(section < cv_terms_.size(), "cvStringToEnum_: Index overflow (section number too large)");
Expand Down

0 comments on commit 331436c

Please sign in to comment.