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

Uncaught exception in builtins.toJSON #12060

Closed
2 tasks done
NaN-git opened this issue Dec 14, 2024 · 0 comments · Fixed by #12127
Closed
2 tasks done

Uncaught exception in builtins.toJSON #12060

NaN-git opened this issue Dec 14, 2024 · 0 comments · Fixed by #12127
Labels
bug good first issue Quick win for first-time contributors idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. language The Nix expression language; parser, interpreter, primops, evaluation, etc

Comments

@NaN-git
Copy link

NaN-git commented Dec 14, 2024

Describe the bug

builtins.toJSON throws an exception, when an input string is not a valid UTF-8 string, e.g.

error: [json.exception.type_error.316] invalid UTF-8 byte at index 308: 0xF7

nix repl quits (crashes?).

Steps To Reproduce

  1. Download test file:
wget -O - https://github.com/flenniken/utf8tests/raw/refs/heads/main/utf8tests.bin | head -n 208 > utf8tests.bin
  1. Evaluate the following Nix expression, e.g. in nix repl:
builtins.toJSON (builtins.readFile ./utf8tests.bin)

Expected behavior

Catch exception and display proper error message.

Or it should be enforced that the file read by builtins.readFile is UTF-8 encoded because these issues propagate to other parts of Nix and Nix assumes implicitly that strings are UTF-8 encoded.

Checklist


Add 👍 to issues you find important.

@NaN-git NaN-git added the bug label Dec 14, 2024
@roberth roberth added the language The Nix expression language; parser, interpreter, primops, evaluation, etc label Dec 18, 2024
@roberth roberth added this to Nix team Dec 18, 2024
@github-project-automation github-project-automation bot moved this to To triage in Nix team Dec 18, 2024
@edolstra edolstra added good first issue Quick win for first-time contributors idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. labels Dec 18, 2024
@edolstra edolstra removed this from Nix team Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Quick win for first-time contributors idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. language The Nix expression language; parser, interpreter, primops, evaluation, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants