Skip to content

Commit 9b1ac12

Browse files
committed
improved error message when include/exlide pattern in PythonResource can't be compiled
1 parent 3b4769b commit 9b1ac12

File tree

1 file changed

+20
-7
lines changed
  • graalpython/com.oracle.graal.python.resources/src/com/oracle/graal/python/resources

1 file changed

+20
-7
lines changed

graalpython/com.oracle.graal.python.resources/src/com/oracle/graal/python/resources/PythonResource.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.List;
5151
import java.util.function.Predicate;
5252
import java.util.regex.Pattern;
53+
import java.util.regex.PatternSyntaxException;
5354

5455
import com.oracle.truffle.api.CompilerDirectives;
5556
import com.oracle.truffle.api.InternalResource;
@@ -146,21 +147,33 @@ private static class ResourcesFilter implements Predicate<Path> {
146147
private final boolean log;
147148
private final Pattern includePattern;
148149
private final Pattern excludePattern;
149-
private final List<String> excluded;
150150
private final String exclude;
151151
private final String include;
152-
private final ArrayList<String> included;
152+
private final List<String> excluded;
153+
private final List<String> included;
154+
private static final String INCLUDE_PROP = "org.graalvm.python.resources.include";
155+
private static final String EXCLUDE_PROP = "org.graalvm.python.resources.exclude";
156+
157+
private static final String LOG_PROP = "org.graalvm.python.resources.exclude";
153158

154159
private ResourcesFilter() {
155-
include = getProperty("org.graalvm.python.resources.include");
156-
exclude = getProperty("org.graalvm.python.resources.exclude");
157-
log = Boolean.parseBoolean(getProperty("org.graalvm.python.resources.log"));
158-
includePattern = include != null ? Pattern.compile(include) : null;
159-
excludePattern = exclude != null ? Pattern.compile(exclude) : null;
160+
include = getProperty(INCLUDE_PROP);
161+
exclude = getProperty(EXCLUDE_PROP);
162+
log = Boolean.parseBoolean(getProperty(LOG_PROP));
163+
includePattern = include != null ? compile(include, INCLUDE_PROP) : null;
164+
excludePattern = exclude != null ? compile(exclude, EXCLUDE_PROP) : null;
160165
included = log ? new ArrayList<>() : null;
161166
excluded = log ? new ArrayList<>() : null;
162167
}
163168

169+
private static Pattern compile(String re, String property) {
170+
try {
171+
return Pattern.compile(re);
172+
} catch (PatternSyntaxException pse) {
173+
throw new IllegalArgumentException("could not compile regex pattern '" + re + "' provided by system property '" + property + "'", pse);
174+
}
175+
}
176+
164177
@Override
165178
public boolean test(Path path) {
166179
String absolutePath = path.toAbsolutePath().toString();

0 commit comments

Comments
 (0)