Error loading package in toplevel
kyp0717 opened this issue · 8 comments
A fatal error was encountered when loading the package into utop. Please see error message below.
utop # #require "ppx_deriving_yaml";;
Line 1, characters 0-4Parse error: illegal begin of top_phrase
Fatal error: exception Exit
Raised at file "string.ml", line 115, characters 25-34
Called from file "src/sexp.ml", line 113, characters 13-47
Thanks.
Hi @kyp0717,
Thanks for the error report -- could you provide some extra details like the version of OCaml and UTOP you are using. I just tried it on my machine and got a different error.
In particular it would be useful if you could try the following and paste the results here:
utop -dsource
#require "ppx_deriving_yaml";;
And then could you also try cloning the repository and running:
cd ppx_deriving_yaml
dune utop
utop # type t = { name : string }[@@deriving yaml]
Again, I appreciate you reporting this bug, thank you :))
Here is the result of utop dsource
:
➜ tmp utop -dsource
│ Welcome to utop version 2.6.0 (using OCaml version 4.10.0)! │
#use "topfind";;
#directory "/home/phage/.opam/4.10.0/lib/findlib";;
#directory "+compiler-libs";;
;;let exec_test s =
let l = Lexing.from_string s in
let ph = (!Toploop.parse_toplevel_phrase) l in
let fmt =
Format.make_formatter (fun _ -> fun _ -> fun _ -> ()) (fun _ -> ()) in
try Toploop.execute_phrase false fmt ph with | _ -> false in
let is_native = (let open Gc in (get ()).stack_limit) = 0 in
let suffix = if is_native then "cmxs" else "cma" in
if not (exec_test "Topfind.reset;;")
then
(Topdirs.dir_load Format.err_formatter
("/home/phage/.opam/4.10.0/lib/findlib/findlib." ^ suffix);
Topdirs.dir_load Format.err_formatter
("/home/phage/.opam/4.10.0/lib/findlib/findlib_top." ^ suffix));;
#remove_directory "+compiler-libs";;
let is_native = (let open Gc in (get ()).stack_limit) = 0 in
let pred = if is_native then "native" else "byte" in
Topfind.add_predicates [pred; "toploop"];
Topfind.don't_load ["findlib"];
Topfind.announce ();;
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
#thread;;
#camlp4o;;
#require "core.top";;
Camlp4 Parsing version 4.10.0
#require "core.syntax";;
Type #utop_help for help about using utop.
I ran opam update
and then reran #require "ppx_deriving_yaml
again in utop. Here is the result:
utop # #require "ppx_deriving_yaml";;
Line 1, characters 0-4Parse error: illegal begin of top_phrase
Fatal error: exception Exit
Raised at file "string.ml", line 115, characters 25-34
Called from file "src/sexp.ml", line 113, characters 13-47
Here is the result of cloning the repo, running dune utop
and creating a type that derived yaml:
## Bash Commands ###
$ git clone https://github.com/patricoferris/ppx_deriving_yaml.git
$ cd ppx_deriving_yaml
$ dune utop
Inside utop:
utop # type t = {name:string;}[@@deriving yaml];;
type t = { name : string; }
val to_yaml : t -> [> `O of (string * [> `String of string ]) list ] = <fun>
val of_yaml :
[> `O of (string * Yaml.value) list ] -> (t, [> `Msg of string ]) result =
<fun>
Also, wanted to let you know that it is also not working properly when running inside a jupyter notebook. When running #require "ppx_deriving_yaml"
in the notebook, nothing seems to happen. The functions were not generated.
Sorry I meant can you run the following:
opam update
opam pin remove ppx_deriving_yaml
opam install ppx_deriving_yaml
utop -dsource
utop # #require "ppx_deriving_yaml";;
Does that still give the error mentioned:
Line 1, characters 0-4Parse error: illegal begin of top_phrase
Fatal error: exception Exit
Raised at file "string.ml", line 115, characters 25-34
Called from file "src/sexp.ml", line 113, characters 13-47
Also what ocaml-jupyter version are you using? Thanks again for helping me track this down 👍
Please see the series of commands performed below ...
➜ ~ opam update
➜ ~ opam pin remove ppx_deriving_yaml
Ok, ppx_deriving_yaml is no longer pinned to git+file:///home/phage/tmp/ppx_deriving_yaml#main (version ~dev)
The following actions will be performed:
↗ upgrade ppx_deriving_yaml ~dev to 0.1.0
Do you want to continue? [Y/n] Y
<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ppx_deriving_yaml.0.1.0] downloaded from cache at https://opam.ocaml.org/cache
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⊘ removed ppx_deriving_yaml.~dev
∗ installed ppx_deriving_yaml.0.1.0
Done.
➜ ~ opam install ppx_deriving_yaml
[NOTE] Package ppx_deriving_yaml is already installed (current version is 0.1.0).
Now running utop -dsource
:
➜ ~ utop -dsource
│ Welcome to utop version 2.6.0 (using OCaml version 4.10.0)! │
#use "topfind";;
#directory "/home/phage/.opam/4.10.0/lib/findlib";;
#directory "+compiler-libs";;
;;let exec_test s =
let l = Lexing.from_string s in
let ph = (!Toploop.parse_toplevel_phrase) l in
let fmt =
Format.make_formatter (fun _ -> fun _ -> fun _ -> ()) (fun _ -> ()) in
try Toploop.execute_phrase false fmt ph with | _ -> false in
let is_native = (let open Gc in (get ()).stack_limit) = 0 in
let suffix = if is_native then "cmxs" else "cma" in
if not (exec_test "Topfind.reset;;")
then
(Topdirs.dir_load Format.err_formatter
("/home/phage/.opam/4.10.0/lib/findlib/findlib." ^ suffix);
Topdirs.dir_load Format.err_formatter
("/home/phage/.opam/4.10.0/lib/findlib/findlib_top." ^ suffix));;
#remove_directory "+compiler-libs";;
;;let is_native = (let open Gc in (get ()).stack_limit) = 0 in
let pred = if is_native then "native" else "byte" in
Topfind.add_predicates [pred; "toploop"];
Topfind.don't_load ["findlib"];
Topfind.announce ();;
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
#thread;;
#camlp4o;;
#require "core.top";;
Camlp4 Parsing version 4.10.0
#require "core.syntax";;
Type #utop_help for help about using utop.
─( 18:38:17 )─< command 0 >───────────────────────────{ counter: 0 }─
utop # #require "ppx_deriving_yaml";;
Line 1, characters 0-4Parse error: illegal begin of top_phrase
Fatal error: exception Exit
Raised at file "string.ml", line 115, characters 25-34
Called from file "src/sexp.ml", line 113, characters 13-47