Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown backtick #12337

Open
roberth opened this issue Jan 23, 2025 · 2 comments
Open

Markdown backtick #12337

roberth opened this issue Jan 23, 2025 · 2 comments
Labels
error-messages Confusing messages and better diagnostics

Comments

@roberth
Copy link
Member

roberth commented Jan 23, 2025

We're living in the age of the markdown backtick. Let's embrace it in Nix.

Proposal

Change all '%s' and '%1%' to `%s` and `%1%`

Effects

  • (+) Clear, visually unambiguous stderr output
  • (+) Renders into inline code spans when pasted into a markdown system such as GitHub, Discourse, etc
  • (-) Slightly more typing when discussing the C++ code in markdown
    Try with ``"`%s`"``
    Use a backtick (`` ` ``)
    renders to
    Try with "`%s`"
    Use a backtick (`)

Background

Nix uses ' apostrophes to demarcate the start and end of code, identifiers, user input, etc, in error messages.
This is occasionally confusing:

  • color information is not always available, including after copy/paste (i.e. when users need help)
  • adds visual noise
  • can be confused for the same ' that is allowed in identifiers, moderately obscuring the difference between 'mapAttrs' and 'mapAttrs''

Meanwhile, I have observed that over the past decade or so:

  • ` has been largely phased out from bash scripts in favor of $( )
  • markdown has won
  • the markdown ` is starting to make its way into stderr

If we were to switch from 'foo' to `foo` in error messages, this will avoid any confusing with the ' used in the language, and it will even render nicely when pasted into markdown-based systems.

@roberth roberth added the error-messages Confusing messages and better diagnostics label Jan 23, 2025
@edolstra
Copy link
Member

Generally in favor of this. Ideally we would have the Error constructor making sure that string arguments are properly escaped so they can actually be rendered as Markdown in the terminal. E.g. instead of

        throw BadStorePath("path '%1%' is not in the Nix store", path);

do

        throw BadStorePath("path %s is not in the Nix store", path);

where the Error constructor would take care of adding backticks around string arguments and escaping any backtick characters in the string. (Worth noting that std::filesystem::path already automatically gets quoted in format strings.)

Also, while we're at it, I'd like to start capitalizing/punctuating errors properly, i.e.

        throw BadStorePath("Path %s is not in the Nix store.", path);

@edolstra
Copy link
Member

Oh and we should probably switch to std::format as well, see #10294. So it would be

        throw BadStorePath("Path {} is not in the Nix store.", path);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-messages Confusing messages and better diagnostics
Projects
None yet
Development

No branches or pull requests

2 participants