return undef for empty list

This allows proper fallback on pkg command if needed.
return immediatly in case of failure