Refactored get_metadata_section to return a Result<T,~str>, added error messages. Closes #6615.