improve error message in case of cycles

@tfoote @wjwwood please review and merge