Exit correctly for invalid graphs