rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Fatal error: exception Invalid_argument("String.sub / Bytes.sub")

Open giraud opened this issue 4 years ago • 16 comments

I have a reasonml/reason-react project that compiles ok with bs-platform 8.4.2. First step is I want to upgrade compiler to rescript 9.1.4. After updating dependencies I do a yarn rescript build and I got several fatal errors on different sources.

ex:

Fatal error: exception Invalid_argument("String.sub / Bytes.sub")
rescript: [434/645] src/grid/TextHeaderRenderer3.ast

this is the only message I got even with -verbose. same error with -with-deps

giraud avatar Jun 23 '21 16:06 giraud

this seems to be a parsing error, is that source code in reason or rescript syntax, is it available?

bobzhang avatar Jun 25 '21 06:06 bobzhang

If it's a parser issue, I should be able to get more info about the error, it's location, etc. Is there a way to get that ?

giraud avatar Jun 26 '21 07:06 giraud

Trying setting environment variable OCAMLRUNPARAM=b to see a stack trace.

cristianoc avatar Jun 26 '21 07:06 cristianoc

it could be a bug, see similar issues: https://github.com/rescript-lang/syntax/pull/435

bobzhang avatar Jun 26 '21 07:06 bobzhang

@cristianoc will try next week

giraud avatar Jun 26 '21 09:06 giraud

This is what I get:

Fatal error: exception Invalid_argument("String.sub / Bytes.sub")
Raised at file "pervasives.ml", line 33, characters 20-45
Called from file "string.ml" (inlined), line 47, characters 2-23
Called from file "super_code_frame.ml", line 141, characters 4-93
Called from file "super_location.ml", line 67, characters 10-183
Called from file "format.ml", line 1276, characters 4-20
Called from file "format.ml", line 1286, characters 32-48
Called from file "format.ml", line 1286, characters 32-48
Called from file "format.ml", line 1276, characters 4-20
Called from file "format.ml", line 1276, characters 4-20
Called from file "format.ml", line 1276, characters 4-20
Called from file "format.ml", line 1337, characters 20-38
Called from file "list.ml", line 100, characters 12-15
Called from file "ast_iterator.ml", line 97, characters 4-28
Called from file "list.ml", line 100, characters 12-15
Called from file "ast_iterator.ml", line 505, characters 8-31
Called from file "list.ml", line 100, characters 12-15
Called from file "ppx_entry.ml", line 59, characters 6-65
Called from file "js_implementation.ml", line 219, characters 2-140
Called from file "rescript_compiler_main.ml", line 57, characters 5-258
Called from file "rescript_compiler_main.ml", line 496, characters 4-90
Re-raised at file "location.ml", line 311, characters 14-25
Re-raised at file "location.ml", line 311, characters 14-25
Re-raised at file "location.ml", line 311, characters 14-25
Re-raised at file "location.ml", line 311, characters 14-25
Re-raised at file "location.ml", line 311, characters 14-25
Re-raised at file "location.ml", line 311, characters 14-25
Called from file "location.ml" (inlined), line 316, characters 31-61
Called from file "rescript_compiler_main.ml", line 506, characters 6-37

the code is closed source and is a mix between reason/rescript.

giraud avatar Jun 29 '21 06:06 giraud

Looks like something crashing when looking at lines around the error, in super-errors. ++ @chenglou

cristianoc avatar Jun 29 '21 07:06 cristianoc

reproducible steps:

  • checkout bs-css (master branch)
  • yarn
  • cd bs-css
  • yarn re:build -> ok
  • in Css_Js_Core.rei change let unsafe: (string, string) => rule; to let unsafe: (. string, string) => rule; but dont change it in impl
  • yarn re:build -> exception

giraud avatar Jul 02 '21 07:07 giraud

in general, error reporting should not trigger an exception, we will provide a fallback on this

bobzhang avatar Jul 05 '21 03:07 bobzhang

can not reproduce on 9.1.4. This may be a windows specific issue, can you confirm with that?

bobzhang avatar Jul 12 '21 06:07 bobzhang

On holidays, I'll test next week

giraud avatar Jul 12 '21 08:07 giraud

@bobzhang it seems to be a Windows issue. I tested the repro case in Ubuntu with yarn, and I got a correct error reporting:

FAILED: src/Css_Js_Core.cmj

  We've found a bug for you!
  /home/dev/bs-css/bs-css/src/Css_Js_Core.re:1092:5-10

  1090 │   );
  1091 │ 
  1092 │ let unsafe = (property, value) => D(property, value);
  1093 │ 
  1094 │ let userSelect = x =>

  The implementation /home/dev/bs-css/bs-css/src/Css_Js_Core.re
       does not match the interface src/Css_Js_Core.cmi:
       Values do not match:
         let unsafe: (string, string) => rule
       is not included in
         let unsafe: (. string, string) => rule
       File "/home/dev/bs-css/bs-css/src/Css_Js_Core.rei", line 77, characters 1-95:
         Expected declaration
       File "/home/dev/bs-css/bs-css/src/Css_Js_Core.re", line 1092, characters 5-11:
         Actual declaration

rescript: [31/36] src/Css_Legacy_Core.cmj

also, on Windows, same behavior with yarn or npm.

giraud avatar Jul 22 '21 05:07 giraud

@giraud It seems super_errors are not robust to handle some invalid input, on Windows you can set BS_VSCODE=1 the env variable to bypass the super errors reporting as a work around.

bobzhang avatar Jul 23 '21 05:07 bobzhang

I confirm I get a correct error output with that env var. is there a place where all these variables are explained ?

giraud avatar Jul 23 '21 06:07 giraud

@giraud This is not supposed to be used. It is that super_errors are buggy, so I added it for a work around.

bobzhang avatar Jul 23 '21 07:07 bobzhang

it seems interesting for ide integration 😄

giraud avatar Jul 23 '21 07:07 giraud

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 07 '23 05:08 stale[bot]