Skip to content

Commit

Permalink
Throw exception for type mismatch in StreamingAlgorithmWrapper
Browse files Browse the repository at this point in the history
Throw a more informative exception on type mismatch in
StreamingAlgorithmWrapper. When the declared type for streaming mode
cannot be matched to the types in standard mode implementation, an
exception will occur (for example, #674). Improve its message text.
  • Loading branch information
dbogdanov committed Feb 1, 2018
1 parent 729878d commit 11405d9
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/essentia/streaming/streamingalgorithmwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,40 @@ void StreamingAlgorithmWrapper::declareOutput(SourceBase& source, NumeralType ty


void StreamingAlgorithmWrapper::synchronizeInput(const std::string& name) {
if (_inputType[name] == TOKEN) {
_algorithm->input(name).setSinkFirstToken(*_inputs[name]);
try {
if (_inputType[name] == TOKEN) {
_algorithm->input(name).setSinkFirstToken(*_inputs[name]);
}
else if (_inputType[name] == STREAM) {
_algorithm->input(name).setSinkTokens(*_inputs[name]);
}
}
else if (_inputType[name] == STREAM) {
_algorithm->input(name).setSinkTokens(*_inputs[name]);
catch(EssentiaException& e) {
std::ostringstream msg;
msg << "While wrapping '" << _algorithm->input(name).name()
<< "' input in the streaming algorithm wrapper for "
<< _algorithm->name() << ":\n" << e.what();
throw EssentiaException(msg);
}
}


void StreamingAlgorithmWrapper::synchronizeOutput(const std::string& name) {
if (_outputType[name] == TOKEN) {
_algorithm->output(name).setSourceFirstToken(*_outputs[name]);
try {
if (_outputType[name] == TOKEN) {
_algorithm->output(name).setSourceFirstToken(*_outputs[name]);
}
else if (_outputType[name] == STREAM) {
_algorithm->output(name).setSourceTokens(*_outputs[name]);
}
}
else if (_outputType[name] == STREAM) {
_algorithm->output(name).setSourceTokens(*_outputs[name]);
catch(EssentiaException& e) {
std::ostringstream msg;
msg << "While wrapping '" << _algorithm->output(name).name()
<< "' output in the streaming algorithm wrapper for "
<< _algorithm->name() << ":\n" << e.what();
throw EssentiaException(msg);
throw EssentiaException(msg);
}
}

Expand Down

0 comments on commit 11405d9

Please sign in to comment.