microsoft / microsoft/STL

Can system_error be modified to add the numerical error code in the message?

Open
#5,782 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

We have logs that contain error messages in various languages like japanese, spanish, french, arabic, etc which causes our bug investigations to be difficult. Having a numerical error code would at least allow us to look up the message online.

Looking at the source, I think the following can be changed in the system_error file in the _System_error class:

Current:
https://github.com/microsoft/STL/blob/85e4b574ca1f127993538673d3560dd4fbb4e27d/stl/inc/system_error#L466-L473

Suggested:

    static string _Makestr(error_code _Errcode, string _Message) { // compose error message
        if (!_Message.empty()) {
            _Message.append(": ");
        }
        _Message.append(to_string(_Errcode.value()));
        _Message.append(" - ");
        _Message.append(_Errcode.message());
        return _Message;
    }

When calling std::exception::what(), the error code would now be included.

This is just a proposition and I don't really mind the format itself. What's important is just the idea of adding the numerical code.

I wish it was possible to force FormatMessage to output english messages, but it doesn't work if the english package is not installed ☹️

Thanks,
Félix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked stl/inc/system_error implementation around lines 466-473 and inspect how _System_error builds its message and how std::exception::what() exposes it. Define a stable format for including the numerical error code, then verify that the resulting message preserves existing behavior while making the code available for multilingual logs.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.