GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve error messages of `curses` by indicating failed C function · Issue #125843 · python/cpython

Improve error messages of curses by indicating failed C function #125843

New issue
Copy link
New issue
Copy link
Closed
Closed
Improve error messages of curses by indicating failed C function#125843
Copy link
Assignees
picnixz
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement

Description

@picnixz
picnixz
opened on Oct 22, 2024
Issue body actions

Feature or enhancement

Proposal:

The curses module raises an exception curses.error with a message of the form "XXX() returned ERR" where XXX is generally the name of the C or Python function that was just called. Most of the time, XXX and the Python function that was called have the same name and XXX is a real curses C function or macro. However, in some cases, this is not the case and the actual curses function that was called has a different name.

For debugging purposes, I suggest adding an attribute to the exception class, say .funcname which holds the name of the macro / function that was called at runtime in the C code. This will help users debug issues. For compatibility reasons, I will not change the current error messages since this could break CI in the wild. In addition, I don't expect users to extract the function name from the error message (if they want to, they should use this new attribute).

I considered also adding which Python function was the bad one, but since the exception is raised from a Python function, I think it's better not to do include an other attribute. If needed, we can always add it later but for now the curses C function name is more important.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-125843: indicate which C function caused a curses.error #125844
  • gh-125843: fix test_curses.test_attributes on x86-64 macOS #134252

Activity

  1. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Oct 22, 2024
  2. picnixz
    self-assigned this
    on Oct 22, 2024
  3. picnixz
    added this to Curses issueson Oct 22, 2024
  4. picnixz
    moved this to Features in Curses issueson Oct 22, 2024
  5. encukou commented on Oct 23, 2024

    @encukou
    encukou
    on Oct 23, 2024
    Member
    More actions

    That's a lot of code to carry. Do you have a use case where the you'd want to get the C function programmatically while debugging?

  6. picnixz commented on Oct 23, 2024

    @picnixz
    picnixz
    on Oct 23, 2024
    MemberAuthor
    More actions

    For me no. But I felt that having the precise function that cause the exception would be worthwhile, without having to change the actual messages that were printed. I took inspiration from OSError and its filename/filename2 attributes.

    I think it could be useful in a debugger or to render a custom error message. Note that having the exact function is important since having the w or mw prefix may change the assumptions the caller may have.

    But it's really a minor feature which I found nice to have. If you think the diff is too large (and it is large because of all the small changes), we can drop it. Note that I included a minor cosmetic change where I shortened the name of some functions just for future maintenance but this commit can be dropped.

  7. encukou commented on Oct 23, 2024

    @encukou
    encukou
    on Oct 23, 2024
    Member
    More actions

    But, is there a debugger that would want to add special handling specifically for curses.error?
    If not, I recommend to drop this.

  8. picnixz commented on Oct 23, 2024

    @picnixz
    picnixz
    on Oct 23, 2024
    MemberAuthor
    More actions

    Not to my knowledge. I still think it's important to know which C function was the one that returned ERR (because the name of the function in the message is not always correct IMO) but if you prefer me to update the messages instead rather than adding an attribute, I can do it. If you think we should lie (a bit) to the user then we can keep the status quo.

  9. encukou commented on Oct 23, 2024

    @encukou
    encukou
    on Oct 23, 2024
    Member
    More actions

    Yes, if it's a genuine improvement, make it for everyone; change the str.

    cc @Yhg1s as the curses expert

  10. picnixz commented on Apr 25, 2025

    @picnixz
    picnixz
    on Apr 25, 2025
    MemberAuthor
    More actions

    I'm back on the PR and I eventually just changed all error messages instead of adding a new class & co.

  11. picnixz
    changed the title [-]Expose the name of the `curses` C function that caused the exception as an attribute of `curses.error`.[/-] [+]Improve error messages of `curses` by including failed C function[/+] on Apr 26, 2025
  12. picnixz
    changed the title [-]Improve error messages of `curses` by including failed C function[/-] [+]Improve error messages of `curses` by indicating failed C function[/+] on Apr 26, 2025
  13. picnixz
    added a commit that references this issue on May 19, 2025

    gh-125843: indicate which C function caused a `curses.error` (#125844)

    ee36db5
  14. picnixz commented on May 19, 2025

    @picnixz
    picnixz
    on May 19, 2025
    MemberAuthor
    More actions

    The rest will be addressed in #133579

  15. picnixz
    closed this as completedon May 19, 2025
  16. github-project-automation
    moved this from Features to Done in Curses issueson May 19, 2025
  17. picnixz
    added a commit that references this issue on May 20, 2025

    gh-125843: fix `test_curses.test_attributes` on x86-64 macOS (#134252)

    e007e62
  18. Pranjal095
    added 2 commits that reference this issue on Jul 12, 2025

    pythongh-125843: indicate which C function caused a `curses.error` (p…

    0b23603

    pythongh-125843: fix `test_curses.test_attributes` on x86-64 macOS (p…

    3ab90e8
  19. taegyunkim
    added 2 commits that reference this issue on Aug 4, 2025

    pythongh-125843: indicate which C function caused a `curses.error` (p…

    ec53a92

    pythongh-125843: fix `test_curses.test_attributes` on x86-64 macOS (p…

    3fd8fd9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @picnixz
    picnixz

Labels

extension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement

Projects

  • Curses issues
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.