Skip to content

feat(file): report a rejected file extension clearly on upload - #153

Open
LukasGold wants to merge 1 commit into
mainfrom
fix/file-upload-extension-error
Open

feat(file): report a rejected file extension clearly on upload#153
LukasGold wants to merge 1 commit into
mainfrom
fix/file-upload-extension-error

Conversation

@LukasGold

Copy link
Copy Markdown
Contributor

Closes #51

Changes

  • WikiFileController.put catches mwclient.errors.APIError around mw_site.upload
  • New reraise_upload_error: on a filetype-* code it raises a ValueError naming the file, the rejected extension and the host; every other API error is re-raised unchanged, with the original chained via __cause__
  • New get_allowed_file_extensions: best-effort siteinfo lookup that appends the accepted extensions to the message, and returns None rather than failing if that query does not work
  • tests/test_wiki_file_upload_errors.py covers the three MediaWiki codes, exception chaining, pass-through of unrelated errors, and the degraded message when siteinfo is unavailable

Rationale

An upload rejected for its extension surfaced only as a raw MediaWiki API code, which does not say what was wrong or which extensions the wiki accepts. MediaWiki uses filetype-banned, filetype-banned-type or filetype-badtype depending on version, so the check matches on filetype rather than an exact code.

The translation lives in a module-level function because exercising put end to end needs a live OSW instance; this way the message logic is unit tested offline and put only delegates.

Known limitation, not addressed here

put calls store_entity before mw_site.upload, so a rejected upload still leaves an orphan WikiFile page behind. That predates this change and needs its own decision about ordering or rollback.

- translate MediaWiki filetype-banned errors into a readable ValueError
- name the offending extension and list the extensions the wiki accepts
- re-raise every other APIError unchanged
- closes #51
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.1.0 (current: v2.0.2).

Changelog preview (truncated)
## v2.1.0 (2026-09-01)

### Features

- **file**: Report a rejected file extension clearly on upload
  ([`bb49392`](https://github.com/OpenSemanticLab/osw-python/commit/bb49392a4fc81801d3662613faae96944dd8ed91))

### Testing

- Rename oold.py to oold_test.py so its tests are collected
  ([`20072a9`](https://github.com/OpenSemanticLab/osw-python/commit/20072a9249cd97126a222c62a70f84e0433343ef))

Preview via python-semantic-release and conventional commits.

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.

Add error message if file upload fails due to not allowed extension

1 participant