Crash with stacktrace when parsing flake.lock with invalid JSON #559

Open
opened 2024-10-25 22:47:17 +00:00 by cobaltcause · 1 comment
Member

Describe the bug

Lix prints a not-particularly-helpful stacktrace and asks for a bug report when it fails to parse a flake.lock with invalid JSON (for example, with git merge conflict markers in it).

Steps To Reproduce

  1. Have a flake
  2. Make the flake.lock contents not valid JSON
  3. Do anything involving parsing the flake.lock
  4. Kaboom

Expected behavior

It should probably not print a whole stacktrace about it nor ask for a bug report, because it isn't really a bug. It would also be nice if the error indicated what exactly failed to parse, because currently there's no indication that it's mad about the flake.lock specifically; I just got lucky with an error message that made it obvious to me.

nix --version output

nix (Lix, like Nix) 2.92.0-dev-pre20241015-f607731

Additional context

Here's the stacktrace I got for this:

Exception: nlohmann::json_abi_v3_11_3::detail::parse_error: [json.exception.parse_error.101] parse error at line 412, column 1: syntax error while parsing object key - invalid literal; last read: '"gitlab.computer.surgery",<U+000A><'; expected string literal
Stack trace:
 0# nix::printStackTrace() in /nix/store/z281b0ha0nf2dpy5jfjxs0w5fhj372s6-lix-2.92.0-dev-pre20241015-f607731/lib/liblixutil.so
 1# 0x00007FE1523377B6 in /nix/store/z281b0ha0nf2dpy5jfjxs0w5fhj372s6-lix-2.92.0-dev-pre20241015-f607731/lib/liblixmain.so
 2# 0x00007FE150EBC20A in /nix/store/y3kdn61k93rq2jx1lj2x72lnsk0l92qh-gcc-13.3.0-lib/lib/libstdc++.so.6
 3# 0x00007FE150EBC275 in /nix/store/y3kdn61k93rq2jx1lj2x72lnsk0l92qh-gcc-13.3.0-lib/lib/libstdc++.so.6
 4# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) in /nix/store/z281b0ha0nf2dpy5jfjxs0w5fhj372s6-lix-2.92.0-dev-pre20241015-f607731/lib/liblixmain.so
 5# 0x00005584254112FB in /run/current-system/sw/bin/nix
 6# 0x00007FE150C3127E in /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libc.so.6
 7# __libc_start_main in /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libc.so.6
 8# 0x0000558425368D25 in /run/current-system/sw/bin/nix

CppNix has a similar issue: https://github.com/NixOS/nix/issues/6151

## Describe the bug Lix prints a not-particularly-helpful stacktrace and asks for a bug report when it fails to parse a flake.lock with invalid JSON (for example, with git merge conflict markers in it). ## Steps To Reproduce 1. Have a flake 2. Make the flake.lock contents not valid JSON 3. Do anything involving parsing the flake.lock 4. Kaboom ## Expected behavior It should probably not print a whole stacktrace about it nor ask for a bug report, because it isn't really a bug. It would also be nice if the error indicated what exactly failed to parse, because currently there's no indication that it's mad about the `flake.lock` specifically; I just got lucky with an error message that made it obvious to me. ## `nix --version` output nix (Lix, like Nix) 2.92.0-dev-pre20241015-f607731 ## Additional context Here's the stacktrace I got for this: ``` Exception: nlohmann::json_abi_v3_11_3::detail::parse_error: [json.exception.parse_error.101] parse error at line 412, column 1: syntax error while parsing object key - invalid literal; last read: '"gitlab.computer.surgery",<U+000A><'; expected string literal Stack trace: 0# nix::printStackTrace() in /nix/store/z281b0ha0nf2dpy5jfjxs0w5fhj372s6-lix-2.92.0-dev-pre20241015-f607731/lib/liblixutil.so 1# 0x00007FE1523377B6 in /nix/store/z281b0ha0nf2dpy5jfjxs0w5fhj372s6-lix-2.92.0-dev-pre20241015-f607731/lib/liblixmain.so 2# 0x00007FE150EBC20A in /nix/store/y3kdn61k93rq2jx1lj2x72lnsk0l92qh-gcc-13.3.0-lib/lib/libstdc++.so.6 3# 0x00007FE150EBC275 in /nix/store/y3kdn61k93rq2jx1lj2x72lnsk0l92qh-gcc-13.3.0-lib/lib/libstdc++.so.6 4# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) in /nix/store/z281b0ha0nf2dpy5jfjxs0w5fhj372s6-lix-2.92.0-dev-pre20241015-f607731/lib/liblixmain.so 5# 0x00005584254112FB in /run/current-system/sw/bin/nix 6# 0x00007FE150C3127E in /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libc.so.6 7# __libc_start_main in /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libc.so.6 8# 0x0000558425368D25 in /run/current-system/sw/bin/nix ``` CppNix has a similar issue: https://github.com/NixOS/nix/issues/6151
cobaltcause added the
bug
label 2024-10-25 22:47:17 +00:00
jade added the
crash 💥
label 2024-11-10 02:45:57 +00:00
Owner

This is a missing try block wherever flake.lock is parsed. At least it's easy to fix.

This is a missing try block wherever flake.lock is parsed. At least it's easy to fix.
jade added the
E/easy
E/help wanted
labels 2024-11-10 02:46:27 +00:00
jade added the
Area/flakes
label 2024-11-13 06:03:29 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#559
No description provided.