Title: marshal replaces the exception raised while writing with a generic ValueError · Issue #156942 · python/cpython · GitHub
Open Graph Title: marshal replaces the exception raised while writing with a generic ValueError · Issue #156942 · python/cpython
X Title: marshal replaces the exception raised while writing with a generic ValueError · Issue #156942 · python/cpython
Description: Bug report The marshal writer does not raise an exception where the error occurs: it records an error code in WFILE.error and converts it into an exception at the end, in w_set_exception(). If an exception was already raised, it is repla...
Open Graph Description: Bug report The marshal writer does not raise an exception where the error occurs: it records an error code in WFILE.error and converts it into an exception at the end, in w_set_exception(). If an e...
X Description: Bug report The marshal writer does not raise an exception where the error occurs: it records an error code in WFILE.error and converts it into an exception at the end, in w_set_exception(). If an e...
Opengraph URL: https://github.com/python/cpython/issues/156942
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"marshal replaces the exception raised while writing with a generic ValueError","articleBody":"# Bug report\n\nThe marshal writer does not raise an exception where the error occurs: it records an error code in `WFILE.error` and converts it into an exception at the end, in `w_set_exception()`. If an exception was already raised, it is replaced with a generic one, and not even chained:\n\n```pycon\n>>> t = ([],)\n>>> t[0].append(t)\n>>> marshal.dumps(t)\nValueError: unmarshallable object\n```\n\nThe message raised in `w_ref()` is `cannot marshal recursion tuple objects`. Also lost are `BufferError` for a non-contiguous buffer, the exception raised while marshalling a set item, and `MemoryError` from `PyUnicode_AsEncodedString()` or `PyLong_Export()`. A failure of `PyList_Sort()`, which sorts set items, is reported as `MemoryError`, although the sorting fails with `TypeError`.\n\nFinally, `ValueError(\"unmarshallable object\")` is used for all unsupported values, including those which are only unsupported in the requested version.\n\nI propose to raise the exception where the error is detected, and keep in `WFILE` only a flag saying that an exception has been raised. This removes `w_set_exception()` and all error codes except one, propagates the original exception, and allows more specific messages:\n\n```pycon\n>>> marshal.dumps(marshal)\nValueError: cannot marshal module objects\n>>> marshal.dumps(slice(1), 4)\nValueError: marshalling slice objects requires version 5 or higher\n```\n\nValues which are too large get `object too large to marshal` and `int too large to marshal`. `\"unmarshallable object\"` disappears, so the code which matches it needs to be updated.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156944\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-09-04T14:44:54Z","url":"https://github.com/python/cpython/issues/156942"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:49d8edce-303b-1082-29b1-b0091b3d3c52 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82D2:1FE434:17FE4B1:1FA638F:6B0209D7 |
| html-safe-nonce | 145854eab7c2304a87952ca8a97ba14df11c27c82f1893b33cf8fc4bcf77deaf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkQyOjFGRTQzNDoxN0ZFNEIxOjFGQTYzOEY6NkIwMjA5RDciLCJ2aXNpdG9yX2lkIjoiNjMxNjcyNjc5OTA5MDk3NzIzOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e3ceea939cdc79c52a8c026a0bef052309690a0e035302cb4383c9f17be0c903 |
| hovercard-subject-tag | issue:5349489884 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/156942/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d92634636395bcfc5959c0dea08144e0416f1286e17810ae86c543e49ba05d20/python/cpython/issues/156942 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d92634636395bcfc5959c0dea08144e0416f1286e17810ae86c543e49ba05d20/python/cpython/issues/156942 |
| og:image:alt | Bug report The marshal writer does not raise an exception where the error occurs: it records an error code in WFILE.error and converts it into an exception at the end, in w_set_exception(). If an e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width