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

Avoid crashing when given input longer than R's buffer #202

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

DavisVaughan
Copy link
Contributor

@DavisVaughan DavisVaughan commented Jan 10, 2024

Addresses posit-dev/positron#1767
Which is this TODO left for ark posit-dev/positron#1326 (comment)

Ideally the frontend will break long inputs up for us, making this redundant, but until then we need to at least avoid crashing.

I've taken the same approach as RStudio, which is to just trim the input if it exceeds the buffer size. This isn't ever a practical issue in RStudio because it seems to split large chunks of input by newlines, and sends one line at a time to R's buffer.

Our previous behavior of just returning without copying anything into the buffer wasn't working, and would result in a crash, presumably because R was expecting something to get copied into the buffer after a read-console iteration.

@DavisVaughan DavisVaughan requested a review from lionel- January 10, 2024 21:38

if input.len() > buflen {
let dropped = &input[buflen..input.len()];
log::error!("Console input too large for buffer. Input has been trimmed, dropping: '{dropped}'.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a case where we also want to log in the user console? Not important though, just a thought about an additional error log level that we might want to implement someday.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe a toast message? Would require some kind of ark -> frontend notification system, maybe we already have that in place for R_ShowMessage(), but idk if it works properly.

Regardless, I'm very optimistic that this will be a non issue when the frontend splits large inputs up.

@DavisVaughan DavisVaughan merged commit 11ce9a6 into main Jan 11, 2024
1 check passed
@DavisVaughan DavisVaughan deleted the fix/large-output-crash branch January 11, 2024 16:47
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.

2 participants