# Error when calling my ppx rewriter on my example code

**URL:** <https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215>\
**Category:** Learning\
**Tags:** ppx\
**Created:** [January 21, 2019, 3:56pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215 "2019-01-21T15:56:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![priyas13](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@priyas13](https://discuss.ocaml.org/u/priyas13)\
**Post date:** [January 21, 2019, 3:56pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/1 "2019-01-21T15:56:45Z")

</div>

I build up the ppx rewriter and compiled it using

ocamlbuild -use-ocamlfind my\_ppx.native

Then when I am calling this my\_ppx.native on my code to produce the transformed code where example.ml is the original file and I am trying to produce the transformed code of it.

ocamlfind ocamlc -ppx my\_ppx.native example.ml -o example.out -package ezjsonm,irmin-unix,lwt.unix -package ppx\_sexp\_conv -package ppx\_bin\_prot -package ocaml-migrate-parsetree.driver-main -linkpkg

I get this error:  
Error while running external preprocessor

Command line: my\_ppx.native ‘/var/folders/z3/4f0t350x0p19n87dxrqw7q5w0000gn/T/camlppx775b61’ ‘/var/folders/z3/4f0t350x0p19n87dxrqw7q5w0000gn/T/camlppxbe4b5c’

I could not understand how to get rid of this error.

---

<div class="post-metadata">

**Author:** ![priyas13](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@priyas13](https://discuss.ocaml.org/u/priyas13)\
**Post date:** [January 21, 2019, 4:47pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/2 "2019-01-21T16:47:47Z")

</div>

I am using

Ocaml 4.05.0

ppx\_tools 5.0+4.05.0

Mac OS High Sierra

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [January 21, 2019, 7:52pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/3 "2019-01-21T19:52:37Z")

</div>

Your ppx rewriter is raising an error when called by the compiler. The error is probably in your ppx code. You may also want to try a simpler example for your test, one that does not require so mny external libraries.

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [January 21, 2019, 8:14pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/5 "2019-01-21T20:14:28Z")

</div>

This is a built-in extension node (as indicated by the `ocaml` prefix)

```auto
[%%ocaml.error "Fail here"]

```

which can be used to signal a ppx error to the compiler.

---

<div class="post-metadata">

**Author:** ![priyas13](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@priyas13](https://discuss.ocaml.org/u/priyas13)\
**Post date:** [January 22, 2019, 12:31am UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/6 "2019-01-22T00:31:11Z")

</div>

I tried to run my rewriter using the flag -dsource, which produces the same kind of error. Is there really a problem with my ppx code because I am able to build the native code of the ppx file successfully? How to debug the errors in the ppx code because during building the native code of it, it produces no error?

[%%ocaml.error ;;"[dalify]: Unavailable dalify-ing type."

;;""]

File “_none_”, line 1:

Error: [dalify]: Unavailable dalify-ing type.

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [January 22, 2019, 8:39am UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/7 "2019-01-22T08:39:05Z")

</div>

Your code can perfectly compile fine and have higher-level errors. It is hard to tell from the available information.  
You could test on a marshalled ast and check that `yourppx input output` outputs correctly a marshalled ast on `output`.

---

<div class="post-metadata">

**Author:** ![priyas13](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@priyas13](https://discuss.ocaml.org/u/priyas13)\
**Post date:** [January 22, 2019, 10:30pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/8 "2019-01-22T22:30:52Z")

</div>

Just for clarification:  
I am using ocamlfind to run my ppx\_rewriter on my code to produce the transformed code. Something like this  
ocamlfind ppx\_tools/ppx\_rewriter my\_ppx.native example.ml

where my\_ppx.native is build using  
ocamlbuild -use-ocamlfind my\_ppx.native

Error:  
**sh: 1 : my\_ppx.native: not found**  
which is followed by  
Error: Error while running external preprocessor.

My question: Is it the case that ocamlfind is not able to find .native so there is the error?Could anyone elaborate the bold portion of the error. I could not understand why my\_ppx.native is not found in sh.

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [January 22, 2019, 10:48pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/9 "2019-01-22T22:48:11Z")

</div>

You want to use `ocamlfind ppx_tools/ppx_rewriter ./my_ppx.native example.ml` (with a `./` prefix) since the current directory is not in PATH by default .

---

<div class="post-metadata">

**Author:** ![priyas13](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@priyas13](https://discuss.ocaml.org/u/priyas13)\
**Post date:** [January 23, 2019, 4:40pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/10 "2019-01-23T16:40:20Z")

</div>

Thanks for your help. I was able to run my ppx rewriter on my example code. But I have several questions:  
(1) So my rewriter works fine for ocaml 4.02.3 version and ppx\_deriving 4.1, ppx\_blob 0.2, ppx\_core 113.33.03, ppx\_driver 113.33.04, ppx\_tools 5.0+4.02.0 .  
I am able to compile my ppx code as well call my rewriter on the example code and I get the desired transformed code.  
(2) Now the question is: I am trying to work for the same project using OCaml 4.07.1. As we all know there has been changes in the Parsetree.mli file between both the version 4.02.3 and 4.07.1. Hence I changed my ppx rewriter code accordingly so that my code compiles with the OCaml 4.07.1 version. I changed my code to make it compatible with OCaml 4.07.1. So my ppx code compiles with OCaml 4.07.1, ppx\_driver v0.11.0, ppx\_tools 5.1+4.06.0, ppx\_deriving 4.2.1, ppx\_blob 0.4.0.  
I am able to produce .native for my ppx rewriter using the command  
ocamlbuild -use-ocamlfind my\_ppx.native  
(3) Now when I am calling my rewriter on the example code:  
ocamlfind ppx\_tools/rewriter ./my\_ppx.native example.ml  
This always produce the transformed .ml file with only [%%ocaml.error…]  
What might be the reason for it? My example.ml is same that I used for the other OCaml version. I corrected the type mismatch error between both the versions.  
Any feedback about what exactly is happening and where should I focus to get rid of the error.

---

<div class="post-metadata">

**Author:** ![priyas13](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@priyas13](https://discuss.ocaml.org/u/priyas13)\
**Post date:** [January 23, 2019, 5:28pm UTC](https://discuss.ocaml.org/t/error-when-calling-my-ppx-rewriter-on-my-example-code/3215/11 "2019-01-23T17:28:25Z")

</div>

Never mind. I solved the problem.
