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

Errors returned to lua #179

Open
soerenmeier opened this issue Sep 9, 2022 · 5 comments
Open

Errors returned to lua #179

soerenmeier opened this issue Sep 9, 2022 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@soerenmeier
Copy link
Contributor

When deserialization fails in a next call this error gets returned from rust:

rust-server/src/lib.rs

Lines 151 to 158 in 4a04655

next.success(lua, &res).map_err(|err| {
mlua::Error::ExternalError(Arc::new(Error::DeserializeResult {
err,
method,
result: pretty_print_value(res, 0)
.unwrap_or_else(|err| format!("failed to pretty print result: {}", err)),
}))
})?;

But in lua only the following line get's outputed: Error retrieving next command: attempt to concatenate a userdata value. This is very misleading.
I tried to debug this but I haven't found anything. Something might be wrong with the lua version of dcs.
Did this works once and is this a known issue?

mlua:
function that passes the error to lua: callback_error
function that converts the mlua error into a string: init_error_registry

@rkusa
Copy link
Collaborator

rkusa commented Sep 9, 2022

This is indeed very unhelpful. I've seen this error too, and as far as I remember, it was caused by the hot-reloading. Are you using the hot-reloading feature by any chance?
It would have been fixed in #150, but we decided to not merge it. If you are using the hot-reloading feature, I am afraid that the only workaround right now would be to not use hot-reloading, or to make a local change similar to: https://github.com/DCS-gRPC/rust-server/pull/150/files#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R168

@soerenmeier
Copy link
Contributor Author

soerenmeier commented Sep 9, 2022

No, I compiled with cargo build --release and then copied dcs_grpc.dll and the pdb file to the mods folder.

For the moment i copied the next function and renamed it to try_next and now call that function from next and log::error the Err case.

@rkusa
Copy link
Collaborator

rkusa commented Oct 5, 2022

I can reproduce it now.

While trying to create a small example that reproduces the error to report the issue to mlua, I've learned that this seems to be caused by DCS' lua.dll instead. I couldn't reproduce it outside of DCS, and then dropped DCS' lua.dll into my example, and boom, error was there.
I unfortunately have no idea, why this is caused by DCS' lua.dll (but I am not surprised either). I've confirmed that DCS runs Lua 5.1.5 and that DCS-gRPC is compiled against exactly this version.

DCS:
image

DCS-gRPC:
https://github.com/DCS-gRPC/rust-server/blob/main/src/lua5.1/include/lua.h#L20

What is strange though, if I download the Lua 5.1.5 release, its dll has clearly a different size (308 KB) compared to the on from DCS (257 KB).

In summary. Not caused by mlua. Seems to be caused by DCS' lua.dll. For now, I have no idea how to solve this (except avoiding to return errors from Rust to Lua).

@rkusa rkusa self-assigned this Oct 5, 2022
@rurounijones rurounijones added the bug Something isn't working label Oct 6, 2022
@soerenmeier
Copy link
Contributor Author

That's weird, probably dcs compiled lua with some special flags or something.

Personally, I would probably just do something like this: soerenmeier@7386d9a the errors are always outputted to the dcs-grpc.log and if the lua version supports it also to lua.

@rkusa
Copy link
Collaborator

rkusa commented Oct 11, 2022

@soerenmeier That is definitely a solution I'd also have in mind 👍. Our only concern in the past was that people tend to look into the dcs.log file for errors and easily forget that there is also a DCS-gRPC.log file. I have some ideas of how to pipe them into dcs.log without having to return them as Lua errors. I'll try to create a POC for that soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants