Skip to content

Commit

Permalink
#2330 - Error diagnostic is not clear in case of wrong percent value…
Browse files Browse the repository at this point in the history
… type (#2712)
  • Loading branch information
AliaksandrDziarkach authored Dec 27, 2024
1 parent 4169910 commit c4ebb74
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/tests/integration/ref/formats/idt_to_ket.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ idt_unresolved_many.ket:SUCCEED
idt_unsplit.ket:SUCCEED
Test '!+A-$#12w12r23e32e33': got expected error 'Invalid symbols in the sequence: !,-,$,#,1,2,w,1,2,2,3,e,3,2,e,3,3'
Test '(Y:)': got expected error 'Invalid IDT ambiguous monomer (Y:)'
Test '(Y:000010af)': got expected error 'Invalid number 'af''
Test '(YY:00330067)': got expected error 'Invalid mixed base - only numerical index allowed.'
Test '+/5Phos/A': got expected error 'Sugar prefix could not be used with modified monomer.'
Test '/': got expected error 'Unexpected end of data'
Expand Down
1 change: 1 addition & 0 deletions api/tests/integration/tests/formats/idt_to_ket.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def find_diff(a, b):
"r(B1:50003000)(B1)": "Unknown mixed base 'B1'",
"(YY:00330067)": "Invalid mixed base - only numerical index allowed.",
"(Y:)": "Invalid IDT ambiguous monomer (Y:)",
"(Y:000010af)": "Invalid number 'af'",
}
for idt_seq in sorted(idt_errors.keys()):
error = idt_errors[idt_seq]
Expand Down
23 changes: 20 additions & 3 deletions core/indigo-core/molecule/src/sequence_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,18 @@ void SequenceLoader::loadIdt(KetDocument& document)
check_mixed_base(mixed_base);
if (ratios_str.size() != 8)
throw Exception("Invalid IDT ambiguous monomer %s", idt_alias.c_str());
ratios.emplace(std::array<float, 4>{std::stof(ratios_str.substr(0, 2)), std::stof(ratios_str.substr(2, 2)),
std::stof(ratios_str.substr(4, 2)), std::stof(ratios_str.substr(6, 2))});
auto stof = [](const std::string& arg) -> float {
try
{
return std::stof(arg);
}
catch (...)
{
throw Error("Invalid number '%s'", arg.c_str());
}
};
ratios.emplace(std::array<float, 4>{stof(ratios_str.substr(0, 2)), stof(ratios_str.substr(2, 2)), stof(ratios_str.substr(4, 2)),
stof(ratios_str.substr(6, 2))});
idt_alias = '(' + mixed_base + ')';
mixed_base = mixed_base[0];
}
Expand Down Expand Up @@ -1491,7 +1501,14 @@ SequenceLoader::MonomerInfo SequenceLoader::readHelmMonomer(KetDocument& documen
auto& opt = options.second.emplace_back(opt_alias, std::optional<float>());
if (count.size() > 0)
{
opt.second = std::stof(count);
try
{
opt.second = std::stof(count);
}
catch (...)
{
throw Error("Invalid number '%s'", count.c_str());
}
no_counts = false;
}
if (ch == ')')
Expand Down

0 comments on commit c4ebb74

Please sign in to comment.