Skip to content

properly raise COMException and check for return code - #115

Open
rheard wants to merge 2 commits into
arsenetar:masterfrom
rheard:issue-94
Open

rheard wants to merge 2 commits into
arsenetar:masterfrom
rheard:issue-94

Conversation

@rheard

@rheard rheard commented Sep 28, 2026 •

Copy link
Copy Markdown

Fixes #94

@arsenetar

Copy link
Copy Markdown
Owner

Some overlap here with #89 as well.

volkanncicek added a commit to volkanncicek/send2trash that referenced this pull request Nov 12, 2026
SHFileOperationW deletes a tree that holds a path of MAX_PATH characters or more permanently instead of recycling it, and still returns success; shortening the top-level path to 8.3 names does not help because the names inside stay long. The legacy backend now walks each path first and raises TrashPermissionError, the error arsenetar#115 uses for the IFileOperation backend, leaving the files in place. The legacy long-path tests expect that now, and a new test covers a short folder holding a long path.
@rheard

rheard commented Nov 12, 2026

Copy link
Copy Markdown
Author

@arsenetar Thanks for looking! I hadn't seen #89 when I opened this but then looked at it shortly after. It does seem to contain the same root cause (pywin32 ignores the callback's return value, so the sink has to raise), so credit to @Dobatymo .

The difference is how the error surfaces. #89 raises a plain exception, so pywin32 prints an "Unexpected exception in gateway method" traceback on every refusal and callers get a generic OSError (E_FAIL). This PR raises COMException(E_ABORT), which pywin32 passes through silently, and converts it to TrashPermissionError. That's the exception the Linux backend uses with Freedesktop when it can't trash, and the one #118 uses for the legacy backend.

#89 does report other per-item errors better. I'm happy to port that with @Dobatymo as co-author, either here or in a follow-up, whichever you prefer.

@arsenetar

Copy link
Copy Markdown
Owner

Ok that sounds reasonable, I think incorporating the other changes as mentioned would be nice.

Co-authored-by: Dobatymo <7647594+Dobatymo@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

File is removed but not to the recycle bin

2 participants