apple / apple/pkl

Glob reading with the `file:` schema fails on some paths

Open
#582 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
11.5k
Forks
402
Avg merge
1d 15h
Merged PRs (30d)
20

Description

The handling of files reads using `read*` is a bit broken at the moment. Behaviour changes depending on whether or not the `file:` schema is used, and behaviour in a `pkl` vs the REPL doesn't always seem consistent. Additionally there are a number of simple glob patterns that cause `NullPointerExceptions`s or similar incorrect behaviour.

Pkl REPL:

```pkl
An unexpected error has occurred. Would you mind filing a bug report?
Cmd+Double-click the link below to open an issue.
Please copy and paste the entire error output into the issue's description, provided you can share it.

https://github.com/apple/pkl/issues/new

java.lang.NullPointerException

–– Pkl Error ––
None (cause has no message)

1 | read*("file:**/*.txt")
^^^^^^^^^^^^^^^^^^^^^^
at (repl:pkl0)

Pkl 0.27.0-dev+7917ddb0c (macOS 15.0, native)

java.lang.NullPointerException
at org.pkl.core.util.GlobResolver.splitGlobPatternIntoBaseAndWildcards(GlobResolver.java:452)
at org.pkl.core.util.GlobResolver.resolveGlob(GlobResolver.java:483)
```

This error is is caused by the [unsafe assumption that `.getPath` always returns a value](https://sourcegraph.com/github.com/apple/pkl/-/blob/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java?L448). We should probably be using [`. getSchemeSpecificPart`](https://docs.oracle.com/javase/8/docs/api/java/net/URI.html#getSchemeSpecificPart--) instead.

Evaling the following will work

```pkl
a = read*("**/*.txt")
```

but not (addition of the `file:` schema)

```pkl
a = read*("file:**/*.txt")
```

and running `read*("**/*.txt")` in the REPL results in

```
read*("**/*.txt")
–– Pkl Error ––
No resource reader is registered for scheme null.

1 | read*("**/*.txt")
^^^^^^^^^^^^^^^^^
at (repl:pkl0)
```

Contributor guide

Open the contributing guide

Research direction

Start in pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java, especially splitGlobPatternIntoBaseAndWildcards around line 448, and reproduce the shown file: glob cases in the Pkl REPL and evaluator. Verify that file:-prefixed and unprefixed glob patterns behave consistently without NullPointerExceptions or an incorrect null-scheme error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.