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

[wpiutil] DataLogWriter constructor doesn't throw when file cannot be created #7531

Open
jwbonner opened this issue Dec 9, 2024 · 1 comment
Labels
type: bug Something isn't working.

Comments

@jwbonner
Copy link
Member

jwbonner commented Dec 9, 2024

Describe the bug
In Java, the constructor of DataLogWriter declared that it throws an IOException if the file cannot be opened. When logging to a path that doesn't exist (/U/logs/... with no USB stick attached), a native error is produced instead which crashes the robot program:

java: /work/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp:582: virtual size_t wpi::raw_fd_ostream::preferred_buffer_size() const: Assertion `FD >= 0 && "File not yet open!"' failed.

This makes it difficult to utilize DataLogWriter even from a background thread, because an incidental error that would prevent logging (like a disconnected USB stick) can crash the robot program on startup. If the constructor throws an exception, this can be properly handled in user/library code.

Expected behavior
The native constructor should catch the error and propagate to Java via JNI. I haven't tested the current behavior with the non-JNI version, but if applicable it should throw a similar error.

@jwbonner jwbonner added the type: bug Something isn't working. label Dec 9, 2024
@KangarooKoala
Copy link
Contributor

I might've gotten this wrong, but I'm guessing this is what happens:

That said, I don't know what the best fix would be.

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

No branches or pull requests

2 participants