Prevent warning "Cannot make an empty frame"
This commit is contained in:
parent
3a35ce4b16
commit
3d3bc94e39
|
@ -35,7 +35,8 @@ const char *Failure::what() const USE_NOTHROW
|
||||||
/*!
|
/*!
|
||||||
* \class TagParser::NoDataFoundException
|
* \class TagParser::NoDataFoundException
|
||||||
* \brief The exception that is thrown when the data to be parsed holds no
|
* \brief The exception that is thrown when the data to be parsed holds no
|
||||||
* parsable information.
|
* parsable information (e.g. relevant section in the file does not exist or
|
||||||
|
* has size of zero).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -88,6 +89,34 @@ const char *InvalidDataException::what() const USE_NOTHROW
|
||||||
return "data to be parsed or to be made seems to be invalid";
|
return "data to be parsed or to be made seems to be invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \class TagParser::NoDataException
|
||||||
|
* \brief The exception that is thrown when the value to be written is empty but that
|
||||||
|
* is not allowed in that context (e.g. an empty ID3v2 frame is not allowed).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Constructs a new exception.
|
||||||
|
*/
|
||||||
|
NoDataProvidedException::NoDataProvidedException() USE_NOTHROW
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Destroys the exception.
|
||||||
|
*/
|
||||||
|
NoDataProvidedException::~NoDataProvidedException() USE_NOTHROW
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns a C-style character string describing the cause of the exception.
|
||||||
|
*/
|
||||||
|
const char *NoDataProvidedException::what() const USE_NOTHROW
|
||||||
|
{
|
||||||
|
return "can not write empty value";
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \class TagParser::TruncatedDataException
|
* \class TagParser::TruncatedDataException
|
||||||
* \brief The exception that is thrown when the data to be parsed is truncated
|
* \brief The exception that is thrown when the data to be parsed is truncated
|
||||||
|
|
|
@ -29,6 +29,13 @@ public:
|
||||||
virtual const char *what() const USE_NOTHROW;
|
virtual const char *what() const USE_NOTHROW;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TAG_PARSER_EXPORT NoDataProvidedException : public Failure {
|
||||||
|
public:
|
||||||
|
NoDataProvidedException() USE_NOTHROW;
|
||||||
|
virtual ~NoDataProvidedException() USE_NOTHROW;
|
||||||
|
virtual const char *what() const USE_NOTHROW;
|
||||||
|
};
|
||||||
|
|
||||||
class TAG_PARSER_EXPORT TruncatedDataException : public InvalidDataException {
|
class TAG_PARSER_EXPORT TruncatedDataException : public InvalidDataException {
|
||||||
public:
|
public:
|
||||||
TruncatedDataException() USE_NOTHROW;
|
TruncatedDataException() USE_NOTHROW;
|
||||||
|
|
|
@ -430,23 +430,7 @@ Id3v2FrameMaker::Id3v2FrameMaker(Id3v2Frame &frame, byte version, Diagnostics &d
|
||||||
{
|
{
|
||||||
const string context("making " % m_frame.idToString() + " frame");
|
const string context("making " % m_frame.idToString() + " frame");
|
||||||
|
|
||||||
// get non-empty, assigned values
|
// validate frame's configuration
|
||||||
vector<const TagValue *> values;
|
|
||||||
values.reserve(1 + frame.additionalValues().size());
|
|
||||||
if (!frame.value().isEmpty()) {
|
|
||||||
values.emplace_back(&frame.value());
|
|
||||||
}
|
|
||||||
for (const auto &value : frame.additionalValues()) {
|
|
||||||
if (!value.isEmpty()) {
|
|
||||||
values.emplace_back(&value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// validate assigned data
|
|
||||||
if (values.empty()) {
|
|
||||||
diag.emplace_back(DiagLevel::Critical, "Cannot make an empty frame.", context);
|
|
||||||
throw InvalidDataException();
|
|
||||||
}
|
|
||||||
if (m_frame.isEncrypted()) {
|
if (m_frame.isEncrypted()) {
|
||||||
diag.emplace_back(DiagLevel::Critical, "Cannot make an encrypted frame (isn't supported by this tagging library).", context);
|
diag.emplace_back(DiagLevel::Critical, "Cannot make an encrypted frame (isn't supported by this tagging library).", context);
|
||||||
throw InvalidDataException();
|
throw InvalidDataException();
|
||||||
|
@ -462,6 +446,25 @@ Id3v2FrameMaker::Id3v2FrameMaker(Id3v2Frame &frame, byte version, Diagnostics &d
|
||||||
diag.emplace_back(DiagLevel::Warning,
|
diag.emplace_back(DiagLevel::Warning,
|
||||||
"The existing flag and group information is not supported by the version of ID3v2 and will be ignored/discarted.", context);
|
"The existing flag and group information is not supported by the version of ID3v2 and will be ignored/discarted.", context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get non-empty, assigned values
|
||||||
|
vector<const TagValue *> values;
|
||||||
|
values.reserve(1 + frame.additionalValues().size());
|
||||||
|
if (!frame.value().isEmpty()) {
|
||||||
|
values.emplace_back(&frame.value());
|
||||||
|
}
|
||||||
|
for (const auto &value : frame.additionalValues()) {
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
values.emplace_back(&value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate assigned values
|
||||||
|
if (values.empty()) {
|
||||||
|
throw NoDataProvidedException();
|
||||||
|
// note: This is not really an issue because in the case we're not provided with any value here just means that the field
|
||||||
|
// is supposed to be removed. So don't add any diagnostic messages here.
|
||||||
|
}
|
||||||
const bool isTextFrame = Id3v2FrameIds::isTextFrame(m_frameId);
|
const bool isTextFrame = Id3v2FrameIds::isTextFrame(m_frameId);
|
||||||
if (values.size() != 1) {
|
if (values.size() != 1) {
|
||||||
if (!isTextFrame) {
|
if (!isTextFrame) {
|
||||||
|
|
Loading…
Reference in New Issue