Repository navigation
StringUtils: make prefix/suffix(char) return whole string when delimiter absent - #9501
Conversation
|
@timosachsenberg The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-06-12 19:32:17.926427885 +0000
+++ AUTHORS.new 2026-06-12 19:32:23.105329884 +0000
@@ -22,8 +22,9 @@
- Chirag Dave
- Chris Bauer
- Chris Bielow
- - Christie Mathews
- Christian Ehrlich
+ - Christie Mathews
+ - Claude
- Clemens Groepl
- Cornelia Friedle
- Daniel Jameson |
📝 WalkthroughWalkthroughStringUtils ChangesStringUtils Delimiter Handling Refactor
TOPPBase Range Parsing Validation
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/openms/include/OpenMS/DATASTRUCTURES/StringUtils.h`:
- Around line 503-504: Update the Doxygen comments for the functions that return
parts before/after a delimiter (the prefix(char) and suffix(char) overloads in
StringUtils.h) to use an `@brief` block followed by a blank line and then the
detailed description: move the current single-line /// descriptions into a
proper `@brief` line, insert a blank line, and then add the rest of the
explanation (e.g., behavior when delim is not found) in the detail section so
the comments conform to the header guideline requiring "`@brief`" plus a
blank-line-separated detail section.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 88a3d2e1-17ca-4204-bfb3-955c4596cb85
📒 Files selected for processing (5)
src/openms/include/OpenMS/DATASTRUCTURES/StringUtils.hsrc/openms/source/FORMAT/FileHandler.cppsrc/openms_gui/source/VISUAL/APPLICATIONS/GUITOOLS/ImageCreator.cppsrc/tests/class_tests/openms/source/String_test.cppsrc/topp/MSGFPlusAdapter.cpp
…ter absent
prefix(s, delim) and suffix(s, delim) previously threw Exception::ElementNotFound
when the delimiter was not present. Throwing a container-lookup exception from a
string-slicing helper is surprising and forced callers to either guard every call
or wrap it in try/catch. It was also the root cause of the MSGFPlusAdapter
scan-number regression: the String->std::string migration dropped the implicit
suffix('=') extraction, and the strict throw turned a benign input into a crash.
Now the missing-delimiter case returns the whole string ("nothing to cut off ->
you get the original back"), giving a simple, symmetric, no-surprises contract.
Fixed the only two call sites that relied on the throw as control flow:
- FileHandler::getTypeByFileName: explicit has('.') guard (preserves Bruker
fid -> XMASS and UNKNOWN handling).
- ImageCreator: explicit has('.') guard (preserves "nosuffix" fallback).
All other char-delim callers either guarantee the delimiter is present or had no
exception handling (so they would previously crash on missing input and now
degrade gracefully). Updated String_test accordingly.
https://claude.ai/code/session_01TzmuvTWtGMmc5hhH8kXK7Y
PR #9450 dropped the implicit suffix('=') when migrating String->std::string, turning a SpecID like "controllerType=0 controllerNumber=1 scan=17" into a ConversionError. With suffix(char) now returning the whole string when the delimiter is absent, the original intent is expressed in a single line and also handles a bare-integer SpecID gracefully. https://claude.ai/code/session_01TzmuvTWtGMmc5hhH8kXK7Y
Conform to developer_coding_conventions: brief description, blank line, then detailed behavior (delimiter-absent case). https://claude.ai/code/session_01TzmuvTWtGMmc5hhH8kXK7Y
3eb9fa0 to
672e4b5
Compare
…misreading With StringUtils::prefix/suffix(.,':') now returning the whole string when the delimiter is absent, a colon-less range like "400" was silently interpreted as the degenerate range 400:400 instead of failing as before. Restore the loud failure: parseRange_ now throws Exception::ConversionError when the mandatory ':' separator (documented format "[min]:[max]") is missing. Valid input (which always contains ':', e.g. ":", "0:0", "600:5000") is unaffected. Adds a regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…hrowing After making StringUtils::prefix/suffix(char) lenient, two broad-catch call sites silently changed behavior on malformed input. Restore the intended behavior explicitly: - RibonucleotideTSVDataProvider::parseRow_: an ambiguity entry whose 10th field lacks the space separator now throws ParseError (so the row is skipped, as before) instead of silently setting both alternative codes to the same single value. - TargetedSpectraExtractor: an identifier without a '_' now leaves PeptideRef empty (as the previous throw-and-catch did) instead of silently using the whole identifier; the dead try/catch is removed. Co-Authored-By: Claude Opus 4.8 <[email protected]>
timosachsenberg
left a comment
There was a problem hiding this comment.
I found one API semantic-change regression risk.
prefix(s, delim) and suffix(s, delim) previously threw Exception::ElementNotFound
when the delimiter was not present. Throwing a container-lookup exception from a
string-slicing helper is surprising and forced callers to either guard every call
or wrap it in try/catch.
Now the missing-delimiter case returns the whole string ("nothing to cut off ->
you get the original back"), giving a simple, symmetric, no-surprises contract.
This does not change behavior for any valid input (a valid delimiter is always present).
Call sites that relied on the old throw as control flow were updated explicitly, so the
lenient contract does not silently change their behavior on malformed input:
fid -> XMASS and UNKNOWN handling).
ConversionError when ':' is missing, instead of silently reading "400" as the degenerate
range 400:400 (affects FileFilter, IDFilter, DTAExtractor, CometAdapter, ImageCreator).
the space separator) throws ParseError and the row is skipped, as before, instead of
duplicating the single value into both alternative codes.
previous throw-and-catch did) rather than using the whole identifier.
MSGFPlusAdapter was also switched to the lenient suffix('=') for scan-number extraction;
this is equivalent to (and replaces) the rfind('=') ternary already on develop, so it is a
cosmetic refactor with no behavior change. Updated String_test and TOPPBase_test accordingly.
https://claude.ai/code/session_01TzmuvTWtGMmc5hhH8kXK7Y
Summary by CodeRabbit
min:maxformat and errors when the:separator is missing.