Skip to content

Fix Kavita notification sending title prefix instead of folder path - #299

Open
rukuh wants to merge 1 commit into
Chaptarr:developfrom
rukuh:fix-kavita-notification-path
Open

rukuh wants to merge 1 commit into
Chaptarr:developfrom
rukuh:fix-kavita-notification-path

Conversation

@rukuh

@rukuh rukuh commented Oct 6, 2026 •

Copy link
Copy Markdown

Description

When notifying Kavita of an imported book, deleted file, or retagged release, Chaptarr was sending $"{header} - {message}" (e.g., "Chaptarr - Book Downloaded - /media/Books/Author/Title") as folderPath to Kavita's POST /api/library/scan-folder endpoint.

Because Kavita's directory traversal logic (DirectoryService.GetFoldersTillRoot) expects an actual filesystem path within the library root, the branded title prefix caused directory peeling to exhaust all slashes, throwing an unhandled ArgumentOutOfRangeException: length ('-1') must be a non-negative value (HTTP 500).

This change:

  • Passes the folder path directly to _kavitaService.Notify without the branded title prefix.
  • Guards against null or whitespace paths before dispatching.
  • Replaces .First() with .FirstOrDefault() when resolving paths from BookFiles to avoid InvalidOperationException on empty collections.
  • Corrects interface parameter names from message to folderPath in IKavitaService and IKavitaServiceProxy.
  • Fixes a copy-pasted log message in Kavita.cs that referenced "Subsonic".
  • Adds unit tests covering all notification events and edge cases in KavitaFixture.

Fixes #

Database Migration

NO

How was this tested?

  • Setup: Docker on Linux (Ubuntu 24.04), running Chaptarr alongside Kavita (jvmilazz0/kavita:latest).
  • Reproduction:
    1. Configured the Kavita notification hook under Settings > Connect.
    2. Imported a book (triggering OnReleaseImport).
    3. Observed Kavita responding with HTTP 500:
      NzbDrone.Common.Http.HttpException: HTTP request failed: [500:InternalServerError] [POST] at [http://kavita:5000/api/library/scan-folder]
      {"status":500,"message":"length ('-1') must be a non-negative value. (Parameter 'length')\nActual value was -1.","details":"at Kavita.Services.DirectoryService.GetFoldersTillRoot..."}
      
    4. Verified payload was sending "Chaptarr - Book Downloaded - /media/Books/...".
  • Verification:
    • Tested POST /api/library/scan-folder with clean folder paths ({"apiKey": "...", "folderPath": "/media/Books/Author/Title"}), which responds HTTP 200 and initiates the

Kavita's library scan-folder endpoint expects an absolute directory path within a configured library. Previously, Chaptarr was sending $"{header} - {message}" (e.g. "Chaptarr - Book Downloaded - /media/Books/Author/Title"), causing Kavita's DirectoryService to fail with a 500 ArgumentOutOfRangeException when resolving parent directories back to root.

This change passes the directory path directly without the branded title prefix, guards against empty book file lists, and corrects the log message.
@rukuh
rukuh requested a review from robertlordhood as a code owner October 6, 2026 20:21
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.

1 participant