Skip to content

Fix OneDrive upload service to report all missing files at once#169221

Merged
zweckj merged 3 commits into
home-assistant:devfrom
leodrivera:fix-onedrive-upload-report-all-missing-files
Apr 28, 2026
Merged

Fix OneDrive upload service to report all missing files at once#169221
zweckj merged 3 commits into
home-assistant:devfrom
leodrivera:fix-onedrive-upload-report-all-missing-files

Conversation

@leodrivera
Copy link
Copy Markdown
Contributor

When uploading multiple files, if more than one file does not exist, only the first missing file was reported and the rest were silently ignored. This was because _read_file_contents raised a HomeAssistantError immediately on the first Path.exists() failure. This PR collects all missing filenames before raising, then surfaces all of them in a single HomeAssistantError using the new filenames_do_not_exist translation key.

Breaking change

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Previously _read_file_contents raised on the first missing file, leaving subsequent missing files unreported. Collect all missing filenames and raise a single HomeAssistantError with all of them listed in the translation placeholder
Copilot AI review requested due to automatic review settings April 26, 2026 22:48
@leodrivera leodrivera requested a review from zweckj as a code owner April 26, 2026 22:48
@home-assistant home-assistant Bot added bugfix cla-signed has-tests integration: onedrive small-pr PRs with less than 30 lines. Top 200 Integration is ranked within the top 200 by usage labels Apr 26, 2026
@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @zweckj, mind taking a look at this pull request as it has been labeled with an integration (onedrive) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of onedrive can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign onedrive Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 the OneDrive upload service’s error reporting so that when multiple filenames are provided, all missing files are reported in a single translated HomeAssistantError rather than failing on the first missing path.

Changes:

  • Update _read_file_contents to collect all missing filenames before raising an error.
  • Add a new filenames_do_not_exist translation key for multi-file missing errors.
  • Extend test coverage to validate that multiple missing files are surfaced together.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
homeassistant/components/onedrive/services.py Collects missing filenames during upload preparation and raises a single translated error after processing inputs.
homeassistant/components/onedrive/strings.json Adds a new exception translation message for multiple missing filenames.
tests/components/onedrive/test_services.py Updates existing missing-file test assertions and adds a new test for multiple missing filenames.

Comment thread homeassistant/components/onedrive/services.py Outdated
Comment thread homeassistant/components/onedrive/services.py Outdated
Comment thread homeassistant/components/onedrive/strings.json Outdated
- Defer stat/read I/O until after all missing filenames are collected,
  avoiding unnecessary filesystem work when any file is absent
- Cache Path.stat().st_size in a local variable to avoid a double
  syscall and a subtle race in the file_too_large error path
- Route single missing file through the existing filename_does_not_exist
  key for more natural phrasing; two or more use filenames_do_not_exist
- Fix "file(s)" wording to "files" in the filenames_do_not_exist message
- Add the missing filenames_do_not_exist entry to translations/en.json
- Update test_filename_does_not_exist to assert the singular key and
  placeholder
Comment on lines +55 to +61
if len(missing) == 1:
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="filename_does_not_exist",
translation_placeholders={"filename": missing[0]},
)
if missing:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't overcomplicate, just having the second error messages (which only show one file), should be understandable enough

Suggested change
if len(missing) == 1:
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="filename_does_not_exist",
translation_placeholders={"filename": missing[0]},
)
if missing:

Copy link
Copy Markdown
Contributor Author

@leodrivera leodrivera Apr 28, 2026

Choose a reason for hiding this comment

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

I wouldn't overcomplicate, just having the second error messages (which only show one file), should be understandable enough

Just to see if I understood your request correctly: you suggest removing singular/plural branching, using filenames_do_not_exist for both 1 and many, right?

If that was what you were thinking, I agree. I made this separation due to concerns about translations of singular/plural strings, but personally, I do not like it either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you confirm this, we should also adjust this same condition in #168064

- Remove the singular error handling for a single missing file, consolidating it to report all missing files at once.
- Update translation keys to reflect the change from "filename_does_not_exist" to "filenames_do_not_exist" for consistency.
- Adjust tests to validate the new error handling behavior for multiple missing files.
Copilot AI review requested due to automatic review settings April 28, 2026 01:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread homeassistant/components/onedrive/services.py
@zweckj zweckj merged commit bf4b865 into home-assistant:dev Apr 28, 2026
36 of 37 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 29, 2026
@leodrivera leodrivera deleted the fix-onedrive-upload-report-all-missing-files branch April 30, 2026 03:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants