Skip to content

Handle the "std::error_code" special for watch window because natvis is insufficient #13340

Open
@StephenApptronik

Description

@StephenApptronik

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions