From 1c676885f824c6f47f4e8ca1d466b14eb39182eb Mon Sep 17 00:00:00 2001 From: Christoph Stelz Date: Wed, 23 Apr 2025 23:55:51 +0200 Subject: [PATCH] More explicit error messages during FASTA parsing Previously, parsing errors in FASTA files were ignored and subsequent sequences quietly dropped. By checking the return value of the parsing routine, the program can now warn the user if illegal characters are encountered and refuses to continue. --- src/msapll.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/msapll.cpp b/src/msapll.cpp index 3773456..d084829 100644 --- a/src/msapll.cpp +++ b/src/msapll.cpp @@ -516,8 +516,9 @@ namespace modeltest /* read FASTA sequences for finding the number of tips and seq len */ /* make sure they are all of the same length */ + int ret; for (cur_seq = 0; - pll_fasta_getnext (fp, &hdr, &hdr_len, &seq, &n_sites_read, &seq_idx); ++cur_seq) + (ret = pll_fasta_getnext (fp, &hdr, &hdr_len, &seq, &n_sites_read, &seq_idx)); ++cur_seq) { if (dt_unknown) { @@ -557,6 +558,14 @@ namespace modeltest free (hdr); } + // Passthrough illegal character errors + if (ret == PLL_FAILURE && (pll_errno == PLL_ERROR_FASTA_ILLEGALCHAR || pll_errno == PLL_ERROR_FASTA_UNPRINTABLECHAR)) { + mt_errno = MT_ERROR_ALIGNMENT; + strncpy(mt_errmsg, pll_errmsg, ERR_MSG_SIZE); + free(hdr); + free(seq); + } + if (sites == MT_SIZE_UNDEF) { switch (pll_errno)