failed to print error code `:s` fail on windows due to encoding error

Open
#4,436 11 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 9 days

@shreyas-s1403 is already working on this.

Since Oct 23, 2026.

  • #4774 by @wyf027 — closed without merging
  • #4883 by @ameliabarnabyhub — closed without merging
  • #4884 by @hannahgreendesk — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
tooling

Research direction

Start by compiling and running the supplied filesystem-error reproducer on Windows, then trace how fmt handles std::error_code with the {:s} formatter. Done means the example prints the error code without an encoding exception while preserving the other displayed values.

Written by the indexing model from the issue text.

Description

#include <exception>
#include <filesystem>
#include <iostream>

#include "fmt/ostream.h"
#include "fmt/std.h"

namespace fs = std::filesystem;

int main() {
    const fs::path from{"/none1/a"}, to{"/none2/b"};

    try {
        fs::copy_file(from, to);
    } catch (fs::filesystem_error const &ex) {
        std::cout << "what():  " << ex.what() << '\n'
                  << "path1(): " << ex.path1() << '\n'
                  << "path2(): " << ex.path2() << '\n'
                  << "code().value():    " << ex.code().value() << '\n'
                  << "code().message():  " << ex.code().message() << '\n'
                  << "code().category(): " << ex.code().category().name() << '\n';

        try {
            fmt::println("{:s}", ex.code());
        } catch (std::exception &e) {
            fmt::println("fmt error: {}", e.what());
        }
    }

    fmt::println("exit");
    return 0;
}

Dominant language
C++
Stars
25.9k
Forks
3.1k
Avg merge
9d 5h
Merged PRs (30d)
13

Getting set up

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.

More from fmtlib/fmt

All issues in fmtlib/fmt

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.