Skip to content

Commit 0592438

Browse files
TreeHunter9Artyom Ivanov
andauthored
refactor(cast format): Improve error message about invalid format (#9093)
Co-authored-by: Artyom Ivanov <artyom.ivanov@red-soft.ru>
1 parent 2b4ec44 commit 0592438

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/common/CvtFormat.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,18 @@ namespace
11001100

11011101
const Format::Patterns pattern = mapFormatStrToFormatPattern(patternStr);
11021102
if (pattern == Format::NONE)
1103-
invalidPatternException(patternStr, cb);
1103+
{
1104+
// An invalid `patternStr` may be incomplete, so just parse it from the beginning up to the separator.
1105+
// Since patterns can be combined without separators, we can print multiple patterns, but it's fine.
1106+
const FB_SIZE_T patternBeginPos = i - patternStr.length();
1107+
for (; i < formatLength; i++)
1108+
{
1109+
if (isSeparator(formatUpper[i]))
1110+
break;
1111+
}
1112+
std::string_view errorPattern(formatUpper.data() + patternBeginPos, i - patternBeginPos);
1113+
invalidPatternException(errorPattern, cb);
1114+
}
11041115
if (outFormatPatterns & pattern)
11051116
cb->err(Arg::Gds(isc_can_not_use_same_pattern_twice) << patternStr);
11061117
if (!patternIsCompatibleWithDscType(desc, pattern))

0 commit comments

Comments
 (0)