Closed Sculas closed 6 days ago
@maaslalani Are you sure you don't have a timeout set? As the PR mentions, this only occurs when f.timeout == 0
(so no timeout set).
Looks like tests are failing. I'll look into it when I'm back.
Sorry you're totally right, I was on an incorrect branch!
I've applied the changes you requested and removed the program
field by introducing RunWithContext(context.Context)
, which made sense anyway because the timeout used context.Background()
instead of accepting an existing context.
Of course, Run()
is kept and just calls RunWithContext(context.Background())
as it did previously as well.
I've fixed the data race as well and all tests now pass with -race
.
@maaslalani Would you be able to look into this soon?
@Sculas This looks great! Thank you!
This PR fixes an issue caused by #276 where aborting a form would return
ErrTimeout
instead, because whenf.timeout == 0
,time.Since(startTime) >= f.timeout
is always true. This was discussed here: https://github.com/charmbracelet/huh/pull/276#discussion_r1646225089This is fixed by simply checking if the error returned by
bubbletea
isErrProgramKilled
, which is already handled bytea.WithContext(ctx)
, making the (erroneous) check unnecessary anyway.I've also added tests for handling timeouts, user aborts, and making sure
ErrUserAborted
is returned instead ofErrTimeout
when a timeout error occurs (the issue mentioned above).This required an extra fieldprogram
for testing to hold thetea.Program
to send messages to theForm
(batchUpdate
cannot be used here because it's managed bytea.Program
).RunWithContext(context.Context)
has been added to support this.