Fix a bug in TopoSort where errors are not returned if a cycle is found. Add test case.