Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/9129_process_groups_bett…
Browse files Browse the repository at this point in the history
…er_error_msg'
  • Loading branch information
martyngigg committed Mar 19, 2014
2 parents 6736519 + d959924 commit 08aac71
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Code/Mantid/Framework/API/src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,8 @@ namespace Mantid
// Don't make the new algorithm a child so that it's workspaces are stored correctly
alg_sptr->setChild(false);

alg_sptr->setRethrows(true);

IAlgorithm* alg = alg_sptr.get();
// Set all non-workspace properties
this->copyNonWorkspaceProperties(alg, int(entry)+1);
Expand Down Expand Up @@ -1298,8 +1300,17 @@ namespace Mantid
} // for each OutputWorkspace property

// ------------ Execute the algo --------------
if (!alg->execute())
throw std::runtime_error("Execution of " + this->name() + " for group entry " + Strings::toString(entry+1) + " failed.");
try
{
alg->execute();
}
catch(std::exception& e)
{
std::ostringstream msg;
msg << "Execution of " << this->name() << " for group entry " << (entry+1) << " failed: ";
msg << e.what(); // Add original message
throw std::runtime_error(msg.str());
}

// ------------ Fill in the output workspace group ------------------
// this has to be done after execute() because a workspace must exist
Expand Down
57 changes: 57 additions & 0 deletions Code/Mantid/Framework/API/test/AlgorithmTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,40 @@ class AlgorithmWithValidateInputs : public Algorithm
};
DECLARE_ALGORITHM(AlgorithmWithValidateInputs)

/**
* Algorithm which fails on specified workspace
*/
class FailingAlgorithm : public Algorithm
{
public:
FailingAlgorithm() : Algorithm() {}
virtual ~FailingAlgorithm() {}
const std::string name() const { return "FailingAlgorithm"; }
int version() const { return 1; }

static const std::string FAIL_MSG;

void init()
{
declareProperty(new WorkspaceProperty<>("InputWorkspace","",Direction::Input));
declareProperty("WsNameToFail", "");
}

void exec()
{
std::string wsNameToFail = getPropertyValue("WsNameToFail");
std::string wsName = getPropertyValue("InputWorkspace");

if ( wsName == wsNameToFail )
{
throw std::runtime_error(FAIL_MSG);
}
}
};

const std::string FailingAlgorithm::FAIL_MSG("Algorithm failed as requested");

DECLARE_ALGORITHM(FailingAlgorithm)

class AlgorithmTest : public CxxTest::TestSuite
{
Expand Down Expand Up @@ -699,7 +733,30 @@ class AlgorithmTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( ws1->readY(0)[0], 234 );
}

void test_processGroups_failOnGroupMemberErrorMessage()
{
makeWorkspaceGroup("A", "A_1,A_2,A_3");

FailingAlgorithm alg;
alg.initialize();
alg.setRethrows(true);
alg.setLogging(false);
alg.setPropertyValue("InputWorkspace", "A");
alg.setPropertyValue("WsNameToFail", "A_2");

try
{
alg.execute();
TS_FAIL("Exception wasn't thrown");
}
catch(std::runtime_error& e)
{
std::string msg(e.what());

TSM_ASSERT("Error message should contain original error",
msg.find(FailingAlgorithm::FAIL_MSG) != std::string::npos);
}
}

private:
IAlgorithm_sptr runFromString(const std::string & input)
Expand Down

0 comments on commit 08aac71

Please sign in to comment.