-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Janet compilation errors don't show line numbers #2285
Comments
Would you mind sharing some minimally reproducing code? |
Certainly. This is the file
Trying to run the above code on TIC80 produces the error In standalone Janet, the same file produces the error |
By the way, what does |
Thanks for the code. I was able to reproduce and did some investigation. The short summary is that it may take some work to get line and column information for this situation. A longer explanation follows for any parties interested in undertaking the work :) I'm not the author of any of the Janet integration code, but IIUC, the lines here: if (janet_dostring(core->currentVM, code, "main", &result)) {
reportError(core, result); look to be part of the code path responsible for the output you reported.
Within janet_eprintf("compile error in %s: %s\n", sourcePath,
(const char *)cres.error); which appear to be what constructs the error string beginning "compile error in". (I didn't see any obvious usable line and column information near these lines.) I think in standalone (As a remark in favor of the above guess, comparing the error messages closely, one can see that the TIC-80 integrated code starts with "compile error in", whereas the standalone janet error has the string "compile error:" following the location information.) @AlecTroemel What do you think of the explanation above?
I don't know. May be someone else does though. [1]
Both |
There is no documentation for this in the wiki (the github search bar has a "Wikis" filter). I found #1653 about |
for the |
Compilation error line numbers... brings back some bad memories 🤣. I definitely remember pounding my head against this. Reading through your notes @sogaiu they seem right on the money. If I remember correctly I believe the issue was that Janet only has line number (stack trace) information within the context of a Janet Fiber. Running cart code is executed within the main default fiber by invoking the "TIC" function within an existing environment, but the compilation step had no fiber associated with it for some reason? At least thats how I interpret this if statement @sogaiu referenced in their post Following the usage of that |
@AlecTroemel Thanks for taking a look and sharing your thoughts. This line (essentially what you linked to): if (cres.macrofiber) { mentions So my current guess is that these lines: if (cres.macrofiber) {
janet_eprintf("compile error in %s: ", sourcePath);
janet_stacktrace_ext(cres.macrofiber, ret, "");
} else {
janet_eprintf("compile error in %s: %s\n", sourcePath,
(const char *)cres.error);
} are just about distinguishing between errors that happened during macroexpansion and those that did not, respectively. I don't know if it would work, but it seems worth trying to see if appropriate line and column number information is available via the May be we can try modifying |
I did a quick experiment and unfortunately got Perhaps that's replicating:
This loop seems to be driven by a Looks like the |
Ok, with the following diff, I get: diff --git a/src/core/run.c b/src/core/run.c
index 25748811..966ee027 100644
--- a/src/core/run.c
+++ b/src/core/run.c
@@ -58,10 +58,16 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
} else {
ret = janet_wrap_string(cres.error);
if (cres.macrofiber) {
- janet_eprintf("compile error in %s: ", sourcePath);
+ janet_eprintf("%d:%d: compile error in %s: ",
+ parser.line,
+ parser.column,
+ sourcePath);
janet_stacktrace_ext(cres.macrofiber, ret, "");
} else {
- janet_eprintf("compile error in %s: %s\n", sourcePath,
+ janet_eprintf("%d:%d: compile error in %s: %s\n",
+ parser.line,
+ parser.column,
+ sourcePath,
(const char *)cres.error);
}
errflags |= 0x02; I don't know how well that would work in general, but when I counted lines and columns in my editor with the cart code provided above, it seemed like it might be appropriate:
Perhaps line 12, column 4 refers to the end of the form being processed? Another idea with the diff is to check for positive values within |
@AlecTroemel Not related to this issue but while looking over code for this issue I noticed When I search the repository, I only see Submitted #2287 -- if it's inappropriate / wrong, please mention :) |
@AlecTroemel For the moment, may be it's better to try something along the lines of your idea:
IIUC, (defn chunks [buf _] (:read f 4096 buf)) which it then uses in a call to But presumably we have the source in a string or buffer so perhaps we can make that available in a similar fashion.
Since Alternatively, I wonder if making a custom |
I've made an attempt at a custom Here is the relevant commit. It also changes @AlecTroemel If you have some time at some point, may be you could give this branch a try? Not sure what cases are covered by this, but it seems to produce some meaningful info for the reproduction case. This approach doesn't check whether the return value from |
I pushed some changes to implement something like:
to the aforementioned branch. Here is the commit with the most relevant changes. I tried putting some intentional errors in cart code in a few different places and at least the reported line numbers seemed sensible. |
@sogaiu just pulled down and built your branch. From playing around it does indeed add the line numbers (and column) numbers which is amazing! thank you for hacking on this. Reading through your changes, they seem really reasonable to me. It makes me wonder in what situation you'd not want >>> for a in [1,2,3]:
... asldkfnal
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'asldkfnal' is not defined Part of me feels like you're original diff could be merged into janet upstream. |
However in either case, @sogaiu you're branch seems like it solves this issue! I'll keep testing that branch on a couple larger tic80 carts. |
@AlecTroemel Thanks a lot for testing -- especially since you have relevant carts and are familiar with the code (^^:
Sounds oddly familiar :)
Though I wasn't sure about potential edge cases, like you were hinting at:
However for this particular case, I thought I'd seen some kind of arrangement to get location info along with something like "<repl>" for the name of source. At the built-in repl I get:
May be the Perhaps we can bug bakpakin about potentially changing |
I tried patching IIUC, the /* Run startup script */
Janet mainfun;
janet_resolve(env, janet_csymbol("cli-main"), &mainfun);
Janet mainargs[1] = { janet_wrap_array(args) };
JanetFiber *fiber = janet_fiber(janet_unwrap_function(mainfun), 64, 1, mainargs);
fiber->env = env;
/* Run the fiber in an event loop */
status = janet_loop_fiber(fiber); and AFAICT So may be the kinds of changes we have in mind won't affect the main |
Ok, I asked in janet-lang/janet#1285 whether there is any interest in modifying |
There's now a PR to janet. |
The PR appears to have been merged. @AlecTroemel I tried the changes with TIC-80 (less change now) and it seemed to work here. May be you could see how it works for you? Specifically what I tried was:
At the time of this writing, there isn't yet a release of Janet that includes the change to |
It looks like there was a new release of Janet. This one appears to contain the changes to @AlecTroemel Perhaps once you're happy that things are working it would make sense to update the version of Janet used by TIC-80? |
@sogaiu I rebuilt tic80 with the version of the janet that included your changes over the weekend.. then totally forgot to respond here 🤦 Everything has been working just as intended for me! I didn't realize how many times I had been missing the compile error line number until I tried using an older build. I agree upgrading Janet here is the thing to do.. reading through the release notes for both 1.30 and 1.31 (tic80 is on 1.29), it looks like there are a lot of other great changes as well! |
@AlecTroemel Thanks for the status update!
Glad to hear it -- hopefully they will work well for @fuxoft and others as well once Janet is upgraded :) Speaking of which, would you like to do a PR for that? |
@sogaiu ya I totally can, I'll create it now so I dont forget |
Thanks! I'll try it out now. |
Looks like Windows builds are not working again -- have commented in the PR. |
@fuxoft nesbox merged @AlecTroemel's PR #2306. I tried building it and it seems to work for me. I think if one scrolls down here, there may be links where a build result is available. May be you can get an appropriate version somehow (whether by building or via a build artifact / result) and let us know if it works for you. |
@fuxoft FYI, I think the latest release contains the changes from #2306. Perhaps this issue has been addressed? |
I think we can close this. |
When I tried to run my Janet code, I got the following error in TIC-80 console:
compile error in main: unexpected type in destruction, got 0
This was a compilation error in my code but there was no line number printed so it was not trivial for me to find the source of the error.
For runtime errors, the line and column numbers are printed correctly.
The text was updated successfully, but these errors were encountered: