From 5ef4cb3f86c20eef1124e60f94e64848ca3384ff Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Sat, 9 Mar 2024 18:05:35 -0800 Subject: [PATCH] Only print the first line of errors in values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before: ``` nix-repl> legacyPackages.aarch64-darwin.pythonPackages.APScheduler «error: Package ‘python-2.7.18.7’ in /nix/store/6s0m1qc31zw3l3kq0q4wd5cp3lqpkq0q-source/pkgs/development/interpreters/python/cpython/2.7/default.nix:335 is marked as insecure, refusing to evaluate. Known issues: - Python 2.7 has reached its end of life after 2020-01-01. See https://www.python.org/doc/sunset-python-2/. You can install it anyway by allowing this package, using the following methods: a) To temporarily allow all insecure packages, you can use an environment variable for a single invocation of the nix tools: $ export NIXPKGS_ALLOW_INSECURE=1 Note: When using `nix shell`, `nix build`, `nix develop`, etc with a flake, then pass `--impure` in order to allow use of environment variables. b) for `nixos-rebuild` you can add ‘python-2.7.18.7’ to `nixpkgs.config.permittedInsecurePackages` in the configuration.nix, like so: { nixpkgs.config.permittedInsecurePackages = [ "python-2.7.18.7" ]; } c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add ‘python-2.7.18.7’ to `permittedInsecurePackages` in ~/.config/nixpkgs/config.nix, like so: { permittedInsecurePackages = [ "python-2.7.18.7" ]; } » ``` After: ``` nix-repl> legacyPackages.aarch64-darwin.pythonPackages.APScheduler «error: Package ‘python-2.7.18.7’ in /nix/store/6s0m1qc31zw3l3kq0q4wd5cp3lqpkq0q-source/pkgs/development/interpreters/python/cpython/2.7/default.nix:335 is marked as insecure, refusing to evaluate.» ``` --- src/libexpr/print.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libexpr/print.cc b/src/libexpr/print.cc index 9d280f6239c6..cea2e95d4fe5 100644 --- a/src/libexpr/print.cc +++ b/src/libexpr/print.cc @@ -500,7 +500,12 @@ class Printer { if (options.ansiColors) output << ANSI_RED; - output << "«error: " << filterANSIEscapes(e.info().msg.str(), true) << "»"; + auto message = filterANSIEscapes(e.info().msg.str(), true); + auto newline = message.find('\n'); + if (newline != std::string::npos) { + message = message.substr(0, newline); + } + output << "«error: " << message << "»"; if (options.ansiColors) output << ANSI_NORMAL; }