Skip to content
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

Integreate Lua warnings in pandoc's logging system. #8685

Merged
merged 2 commits into from
Jun 22, 2023
Merged

Conversation

tarleb
Copy link
Collaborator

@tarleb tarleb commented Mar 13, 2023

Lua 5.4 added the option to raise warnings with the warn function. This PR adds these warnings to the list of log messages and reports them together with the other logging events.

E.g.

warn('This is the last warning!')
print(pandoc.json.encode(PANDOC_STATE.log[#PANDOC_STATE.log]))
[WARNING] Lua warning at ../testing/test.lua:1:  This is the last warning!
{"message":"This is the last warning!","position":"../testing/test.lua:1: ","type":"LuaWarning","verbosity":"WARNING"}

@jgm
Copy link
Owner

jgm commented Mar 13, 2023

Sounds good. The parameter is just a text. Where does the "position" come from in the structured JSON output?
Is it somehow parsing that out of the text? Would it be better to have a SourcePos as a parameter of the constructor?

@tarleb
Copy link
Collaborator Author

tarleb commented Mar 13, 2023

The position is created with (a wrapper for) the luaL_where function, hence the slightly weird format. A more fine-grained position would require access to Lua's debugging interface, but I haven't written any wrappers for that yet. But we could also parse the line number from the position string and report the file and line number separately in the JSON message.

@jgm
Copy link
Owner

jgm commented Mar 13, 2023

I'm not so much concerned with the JSON message but with the pandoc log message constructor -- just asking whether it should have a SourcePos parameter in addition to the Text. I don't really understand any of the details here, just raising the question.

@tarleb
Copy link
Collaborator Author

tarleb commented Mar 13, 2023

I'll explore that some more. The one downside would be that the SourcePos wouldn't be entirely precise, as Lua debugging info does not contain any column info. We'd have to just set the column to 1 for all Lua warnings, which seems fine.

@tarleb
Copy link
Collaborator Author

tarleb commented Mar 13, 2023

The above script would now generate

[WARNING] Scripting warning at ../testing/test.lua line 1 column 1: This is the last warning!
{"column":1,"line":1,"message":"This is the last warning!","source":"../testing/test.lua","type":"ScriptingWarning","verbosity":"WARNING"}

The SourcePos is wrapped in a Maybe as Lua is not guaranteed to return a useful value. E.g., there won't be a source position if the warning happened in a C function.

Lua's warning system is plugged into pandoc's reporting architecture.
Warnings that are raised with the Lua `warn` function are now reported
together with other messages.
@jgm jgm merged commit 5beb7a1 into jgm:main Jun 22, 2023
10 of 13 checks passed
@tarleb tarleb deleted the lua-warnings branch September 28, 2023 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants