liquidsoap icon indicating copy to clipboard operation
liquidsoap copied to clipboard

Please add better error reporting when there is an error in included files

Open brenc opened this issue 1 year ago • 3 comments

I've split my rather complex configuration up into numerous files that get included from the main script. Whenever there is a syntax error in an included file, the only error output I get is this:

At /app/main.liq, line 34, char 0-25:
%include "lib/inputs.liq"
Error 2: Parse error

This isn't usually a problem when I'm actively developing features as I usually know what I did to cause the error. However, now I'm upgrading to 2.2.x and fixing what comes up. There are one or more errors in an included file. All I can do is comment out lines until it loads then uncomment lines until I find the error. Then it can be really challenging to figure out exactly what the error is.

It would be super helpful to have error output that shows exactly where the error is in the included file.

brenc avatar May 18 '23 19:05 brenc

I just had a look at this. This is not possible at the moment due to the rather low-level nature of the %include directive. We plan on adding propoer modules with v2.3.x which should provide more flexibility with parsing and fix this issue.

toots avatar May 21 '23 18:05 toots

I am pretty sure that we had proper support for this back in the time and it got broken at some point. Isn't it the case?

smimram avatar May 21 '23 19:05 smimram

We still do but not at the level where these errors are being raised. The includer pre-processor does create a lexbuf with the proper filename: https://github.com/savonet/liquidsoap/commit/1c6cd809e61dfe926e42e379d6bee19b19413fd4 but the problem is that inclusion is essentially parser-level merge of the token content. In this case, the included file proceeds without issues and it's the next token read that fails back from the main file.

Here's an extreme example to illustrate: main.liq:

%include "partial_function.liq"
x
end

f(1)

partial_function.liq:

def f(x) =
  print("got variable #{x}")

toots avatar May 21 '23 19:05 toots