- Revision
- 1118
- Author
- paul
- Date
- 2009-03-04 08:57:39 -0600 (Wed, 04 Mar 2009)
Log Message
try to wrap regex exception, as the user will be clueless as to what to do next without it
Modified Paths
Diff
Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java (1117 => 1118)
--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java 2009-02-25 00:34:43 UTC (rev 1117) +++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java 2009-03-04 14:57:39 UTC (rev 1118) @@ -75,21 +75,34 @@ } } - private List<String> splitScenarios(String allScenariosInFile) { + @SuppressWarnings("serial") + public static class InvalidPatternException extends RuntimeException { + public InvalidPatternException(String message, Throwable cause) { + super(message, cause); + } + + } + + private List<String> splitScenarios(String allScenariosInFile) { Pattern scenarioSplitter = patternToPullScenariosIntoGroupFour(); Matcher matcher = scenarioSplitter.matcher(allScenariosInFile); int startAt = 0; List<String> scenarios = new ArrayList<String>(); - if (matcher.matches()) { - while (matcher.find(startAt)) { - scenarios.add(matcher.group(1)); - startAt = matcher.start(4); - } - } else { - String loneScenario = allScenariosInFile; - scenarios.add(loneScenario); - } - return scenarios; + try { + if (matcher.matches()) { + while (matcher.find(startAt)) { + scenarios.add(matcher.group(1)); + startAt = matcher.start(4); + } + } else { + String loneScenario = allScenariosInFile; + scenarios.add(loneScenario); + } + } catch (StackOverflowError e) { + // TODO - wish we had the scenario file name here. + throw new InvalidPatternException("Regex failure for scenario. See http://jbehave.org/documentation/regex-stack-overflow-errors", e); + } + return scenarios; } private Pattern patternToPullScenariosIntoGroupFour() {
To unsubscribe from this list please visit:
