-
Notifications
You must be signed in to change notification settings - Fork 114
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
crash with Fatal error: exception Zed_string.Invalid #334
Comments
To confirm that this remains an issue, I can reproduce it on utop v.2.6.0: $ utop
───────────────────────────────┬─────────────────────────────────────────────────────────────┬───────────────────────────────
│ Welcome to utop version 2.6.0 (using OCaml version 4.09.0)! │
└─────────────────────────────────────────────────────────────┘
Findlib has been successfully loaded. Additional directives:
#require "package";; to load a package
#list;; to list the available packages
#camlp4o;; to load camlp4 (standard syntax)
#camlp4r;; to load camlp4 (revised syntax)
#predicates "p,q,...";; to set these predicates
Topfind.reset();; to force that packages will be reloaded
#thread;; to enable threads
Type #utop_help for help about using utop.
─( 14:23:08 )─< command 0 >───────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # "\158\214\149";;
Fatal error: exception Zed_string.Invalid("at position 16: individual combining marks encountered", "- : string = \"\194\158\214\149\"\n")
|
So I tried with a backtrace: $ env OCAMLRUNPARAM=b utop
───────────────────────────────┬─────────────────────────────────────────────────────────────┬───────────────────────────────
│ Welcome to utop version 2.6.0 (using OCaml version 4.09.0)! │
└─────────────────────────────────────────────────────────────┘
(* ... *)
utop # "\158\214\149";;
Fatal error: exception Zed_string.Invalid("at position 16: individual combining marks encountered", "- : string = \"\194\158\214\149\"\n")
Raised at file "src/zed_string.ml", line 23, characters 29-88
Called from file "src/zed_string.ml", line 211, characters 14-30
Called from file "src/zed_string.ml", line 295, characters 23-43
Called from file "src/lTerm_text_impl.ml", line 24, characters 65-96
Called from file "src/lib/uTop_main.ml", line 301, characters 17-42
Called from file "src/lib/uTop_main.ml", line 810, characters 30-61
Re-raised at file "parsing/location.ml", line 898, characters 22-25
Called from file "src/lib/uTop.ml", line 114, characters 2-11
Called from file "src/lib/uTop_main.ml", line 816, characters 21-61
Called from file "src/lib/uTop_main.ml", line 1555, characters 8-17
Called from file "src/lib/uTop_main.ml", line 1570, characters 4-25 It appears this conversion https://github.com/ocaml-community/utop/blob/master/src/lib/uTop_main.ml#L301 Since a conversion failure is possible (we are calling an unsafe function), I guess a reasonable fix would be to keep the "unstyled string" in this case. I don't know if a "partial styling" is possible. |
I understand that |
Hi, Yes, I agree that it's a bug and that printing a string should never result in an exception. The core issue seems to be that ocaml strings are just a sequence of bytes, and many operations that utop does only work strings that are valid utf8 encodings. That's why there are When rendering an output phrase, we only have a string, and we don't know if it's valid utf8. So it seems that there's a sort of preprocessing phase: Lines 300 to 301 in 7bc5117
My understanding is that |
I just noticed that in the case of long strings, it just does not attempt to do any styling: Lines 297 to 298 in 7bc5117
This can be a reasonable fallback in case of an exception if there's no easy way to alter |
OK, I've now taken a look at this. My best attempt is to wrap the relevant part of let render_out_phrase term string =
if String.length string >= 100 * 1024 then
LTerm.fprint term string
else
try
begin
let string = fix_string string in
let styled = LTerm_text.of_utf8 string in
let stylise loc token_style =
for i = loc.idx1 to loc.idx2 - 1 do
let ch, style = styled.(i) in
styled.(i) <- (ch, LTerm_style.merge token_style style)
done
in
UTop_styles.stylise stylise (UTop_lexer.lex_string string);
LTerm.fprints term styled
end
with (Zed_string.Invalid _) ->
(Printf.printf "got you!\n%!";
LTerm.fprint term (fix_string string)) I think I'm bitten by this design decision of LambdaTerm:
This means a Further input is welcome! |
I also just hit this issue, on a longer input (~350 bytes) but with the same error:
|
I use utop in combination with QCheck - for randomized property-based testing.
However, sometimes when I inspect or illustrate QCheck's ability to produce random strings I encounter a crash.
To reproduce:
Note how I explicitly set the random seed to
12
to attempt something reproducable.On my machine (MacBook Pro, 64-bit, 3,1 GHz Intel Core i5, w/MacPorts), this consistently crashes utop.
Thus if this particular seed does not crash your machine, try another.
I just started from 1 myself, before I hit the number 12.
I've then managed to reduce the crashing string into the following minimal one:
Since I'm not familiar with utop's internals, I cannot tell if this may be a bug in Zed.
The text was updated successfully, but these errors were encountered: