microsoft / microsoft/vscode-cpptools
Handle the "std::error_code" special for watch window because natvis is insufficient
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Feature Request
The type "std::error_code" is part of the standard library for communicating errors when not using exceptions in C++. When an error is set, it constructs an object that is an integer and a reference to an object that can translate that integer into a string. However, the Watch window by default displays errors like this:
err = std::error_code = {std::_V2::error_category: 2}
I have no idea what that error means. To get the message string, one has to invoke err.message(). That invocation is legal in the watch window. For an error type on the stack, I can do that, although it is annoying that I cannot simply add a watch to err or get that info through hover. When the error is embedded in a cluster of more information, it gets harder.
Currently natvis cannot be taught how to display the message because that involves invoking a function. Is there any way to add the view functionality for err specifically without opening up the full can of worms that is arbitrary function invocation?
I would like the CPP extension to handle std::error_code special in the watch window to display the code and the message translation automatically. I realize this opens the doors to running code with side-effects, but as a fundamental part of the language that is common usage (Google style does not allow exceptions, for example), I think it is worth handling special.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the C++ extension's watch-window rendering and its natvis handling, using the issue's std::error_code example as the expected case. Determine where a special display could expose both the numeric code and translated message without enabling arbitrary function invocation; done means the watch and hover views show that information reliably.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, typescript, vscode
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100