Skip to content

Make glob() failure return a RuntimeException - #1653

Merged
cpeel merged 1 commit into
DistributedProofreaders:masterfrom
bpfoley:level-7-glob
Sep 28, 2026
Merged

cpeel merged 1 commit into
DistributedProofreaders:masterfrom
bpfoley:level-7-glob

Conversation

@bpfoley

@bpfoley bpfoley commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

This can only happen in some limited scenarios, none of which we can do anything about at runtime:

  • if PHP runs out of memory while processing the glob;
  • if the pattern is longer than MAXPATHLEN (typically 4kB);
  • if the flag to glob is invalid

If these happen, glob() returns false.

By contrast, not having permission to read the directory, or not matching the pattern returns an empty array.

glob() returning false causes PHP to error with type mismatchs in all the following code (which assumes glob() returned an array). By throwing our own RuntimeException we get better error messages, and quell some PHPStan level 7 warnings.

Comment thread pinc/archiving.inc Outdated
This can only happen in some limited scenarios, none of which we
can do anything about at runtime:
- if PHP runs out of memory while processing the glob;
- if the pattern is longer than MAXPATHLEN (typically 4kB);
- if the flag to glob is invalid

If these happen, `glob()` returns `false`.

By contrast, not having permission to read the directory, or
not matching the pattern returns an empty array.

`glob()` returning false causes PHP to error with type mismatchs in
all the following code (which assumes `glob()` returned an array).
By throwing our own RuntimeException we get better error messages,
and quell some PHPStan level 7 warnings.
@cpeel
cpeel merged commit b3698d3 into DistributedProofreaders:master Sep 28, 2026
12 checks passed
@bpfoley
bpfoley deleted the level-7-glob branch September 28, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants