Skip to content

fix(dav): Handle GenericFileException when reading default contact file#61485

Open
kesselb wants to merge 2 commits into
masterfrom
handle-generic-file-exception
Open

fix(dav): Handle GenericFileException when reading default contact file#61485
kesselb wants to merge 2 commits into
masterfrom
handle-generic-file-exception

Conversation

@kesselb

@kesselb kesselb commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

How to test:

  • Login as admin
  • Go to groupware section
  • Try to download default contact

Main: 500er page when downloading the default event
Here: Default event is downloaded

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Assisted-by: ClaudeCode:claude-sonnet-4-6

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
@kesselb kesselb added this to the Nextcloud 35 milestone Jun 21, 2026
@kesselb kesselb requested a review from a team as a code owner June 21, 2026 19:34
@kesselb kesselb requested review from come-nc, icewind1991, leftybournes and provokateurin and removed request for a team June 21, 2026 19:34
@kesselb kesselb self-assigned this Jun 21, 2026
@kesselb kesselb added bug 3. to review Waiting for reviews labels Jun 21, 2026
@kesselb

kesselb commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

/backport to stable34

@kesselb

kesselb commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

/backport to stable33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves robustness of DAV example content downloads by handling file read failures (notably GenericFileException) when loading stored default contact/event files, avoiding user-facing 500 errors and falling back to bundled defaults where appropriate.

Changes:

  • Catch GenericFileException when reading a stored default contact vCard and return null (allowing controller fallback).
  • Catch GenericFileException when reading a custom example event ICS and rethrow as ExampleEventException.
  • Add/extend unit tests covering these new error-handling paths.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
apps/dav/lib/Service/ExampleEventService.php Extend custom event file read exception handling to include GenericFileException.
apps/dav/lib/Service/ExampleContactService.php Wrap default contact file read in try/catch and log on GenericFileException, returning null for fallback behavior.
apps/dav/tests/unit/Service/ExampleEventServiceTest.php Add unit coverage for custom event read failure via GenericFileException.
apps/dav/tests/unit/Service/ExampleContactServiceTest.php Add unit coverage for missing folder/file and read errors when fetching the default contact.
Comments suppressed due to low confidence (1)

apps/dav/lib/Service/ExampleEventService.php:114

  • ISimpleFile::getContent() can also throw OCP\Lock\LockedException (per interface) but it is not caught here. That means downloading/using a custom example event can still result in an uncaught exception and a 500, despite the method docblock stating it throws ExampleEventException when reading fails.
		try {
			return $icsFile->getContent();
		} catch (NotFoundException|NotPermittedException|GenericFileException $e) {
			throw new ExampleEventException(
				'Failed to read custom example event',
				0,
				$e,
			);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +51 to 58
try {
return $folder->getFile('defaultContact.vcf')->getContent();
} catch (NotFoundException $e) {
return null;
} catch (GenericFileException $e) {
$this->logger->error('Could not read default contact file', ['exception' => $e]);
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants