requestty icon indicating copy to clipboard operation
requestty copied to clipboard

divisor of zero error requestty-ui-0.3.0 in MacOS 12.3.1 Docker 4.5.0 (74594)

Open eNipu opened this issue 2 years ago • 6 comments

thread 'main' panicked at 'attempt to calculate the remainder with a divisor of zero', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/requestty-ui-0.3.0/src/prompt.rs:149:14
                                                                       note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I am getting the following error when I am using the requestty = "0.3.0". Docker Engine version is: 20.10.12.

But I'm not getting the same error in Ubuntu.

eNipu avatar Apr 28 '22 09:04 eNipu

I get get this non-deterministically with docker. Pretty annoying

docker run -t -a stdin -a stdout -a stderr container will default to None for prompts

and docker run -it container works hit or miss

I think this is a dupe of #10 as well. This is more so an issue of the backend interacting with docker from what I can tell. The default crossterm fails, but using termion also produces the same behavior. It'd be nice to have a "I'll try my best" backend, and have a meaningful failure error if we can.

I don't understand the details of how termion/ crossterm work though? Maybe we can pass something into docker that will work for them

dmadisetti avatar Apr 29 '22 20:04 dmadisetti

A quick hack is to introduce a delay. e.g. sleep 0.1 before calling your script in docker run. Annoying, but works reliably now.

This doesn't solve the overall problem (failure on 0 size terminal), but at least allows for use inside docker.

dmadisetti avatar Apr 29 '22 20:04 dmadisetti

@dmadisetti the quick hack solved the issue :-) The issue is related to docker in Intel Mac and Windows CMD. M1 silicon and Ubuntu had no issue.

Anyway, thanks for the quick fix.

eNipu avatar May 02 '22 05:05 eNipu

I think this is a dupe of #10 as well. This is more so an issue of the backend interacting with docker from what I can tell. The default crossterm fails, but using termion also produces the same behavior. It'd be nice to have a "I'll try my best" backend, and have a meaningful failure error if we can.

This library is meant to show interactive prompts, and so just printing out everything is not enough as it needs to keep track of where things are printed so it can overwrite particular parts of the screen as necessary. To do this it keeps track of the screen usage through a struct called Layout which is then changed by the various UI elements to reflect used space.

This divide by zero occurs when trying to divide the number of characters to be displayed by the width of the screen (the screen has zero width?). I'm not sure whether the error occurs with docker not giving the correct screen dimensions or both the backends not being able to report the correct dimensions, but I don't think anything can be changed to make the library more tolerant to zero width.

Lutetium-Vanadium avatar May 19 '22 10:05 Lutetium-Vanadium

Hmm maybe a built in wait on division by 0, then a useful message if it fails after a wait?

dmadisetti avatar May 19 '22 10:05 dmadisetti

Hmm. The wait part seems like a hacky workaround that shouldn't be in the library. However, adding a check for zero sized screens to error instead of panicking seems like a good idea

Lutetium-Vanadium avatar May 19 '22 12:05 Lutetium-Vanadium