Skip to content

[Bug]: MEDIA file not found sends message to main room instead of thread #32503

@Dimaff355

Description

@Dimaff355

Bug Description

When sending a MEDIA file that does not exist, _send_local_file() sends an error message (file not found: /path) to the main room instead of the intended thread. This happens because the error message bypasses thread routing — metadata (containing thread_id) is not properly handled.

Steps to Reproduce

  1. Send a message with MEDIA:/nonexistent/path/file.png in a Matrix thread
  2. The file does not exist
  3. Error message (file not found: /path) appears in the main room, not the thread

Expected Behavior

Current code (gateway/platforms/matrix.py, ~line 1359)

if not p.exists():
    return await self.send(
        room_id, f"{caption or ''}\n(file not found: {file_path})", reply_to,
        metadata=metadata
    )

Actual Behavior

Proposed fix

Silently skip the missing file and log a warning:

if not p.exists():
    logger.warning("Matrix: MEDIA file not found, skipping: %s", file_path)
    return SendResult(success=False, error=f"file not found: {file_path}")

This avoids sending confusing error messages to the wrong location.

Environment

  • Platform: Matrix
  • Use case: Sending generated files that may fail to create

### Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

### Messaging Platform (if gateway-related)

_No response_

### Debug Report

```shell
-

Operating System

Ubuntu 24.04

Python Version

No response

Hermes Version

No response

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliveryplatform/matrixMatrix adapter (E2EE)type/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions