Skip to content

Report an error instead of crashing on a bad --path - #705

Open
wanjinhao1 wants to merge 1 commit into
nextcloud:mainfrom
wanjinhao1:agent/fix-704-bad-path-error
Open

wanjinhao1 wants to merge 1 commit into
nextcloud:mainfrom
wanjinhao1:agent/fix-704-bad-path-error

Conversation

@wanjinhao1

Copy link
Copy Markdown

Fixes #704

Problem

preview:generate-all --path=<path> crashes with an unhandled exception instead of printing an error, in two cases:

  1. The path is not inside the user's files folder (e.g. --path=/alice or --path=/alice/files_trashbin): getRelativePath() returns null (it does not throw), null is passed to $userFolder->get() and ends in a TypeError.
  2. The path is inside the files folder but does not exist (e.g. --path=/alice/files/nope): $userFolder->get() throws NotFoundException, but the call sits outside the try/catch (NotFoundException) block, so the existing "Path not found" message is never printed.

Changes

In generatePathPreviews() (lib/Command/Generate.php):

  • Check getRelativePath() for null and print Path is outside of user's files folder: <path> before anything can pass null to get().
  • Move the $userFolder->get($relativePath) call inside the try/catch (NotFoundException) block so a missing path prints Path not found: <path> instead of crashing, and the loop over the remaining --path values continues.

Testing

No PHP toolchain was available in this environment, so php -l and the unit suite could not be run locally. The change is a control-flow reorder of existing statements with no new dependencies; both cases from the issue report now take the early-return path with a message. Would appreciate a CI run.


This contribution was prepared with AI assistance and was reviewed by the contributor (@wanjinhao1).

Signed-off-by: wanjinhao1 <394959433@qq.com>
@wanjinhao1
wanjinhao1 force-pushed the agent/fix-704-bad-path-error branch from 15fb04b to 3e396a3 Compare November 17, 2026 16:09
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.

Generate-all --path crashes instead of reporting a bad path

1 participant