Fix error when preview command failed to start
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent 5524149 · Browse files · 1 file·+38 added−36 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+38 added−36 removed
- other:+38 added−36 removed
Provenance
- Commit
eaa413c- Tree
ffbf0e3- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
5524149
1 file changed+38 added−36 removed
modified:src/terminal.go+38 added-36 removed
1853 unmodified lines1854 cmd.Stderr = cmd.Stdout1855 reader := bufio.NewReader(out)1856 eofChan := make(chan bool)1857 finishChan := make(chan bool, 1)1858- reapChan := make(chan bool)1858 err := cmd.Start()1860- reaps := 01861- if err != nil {1862- t.reqBox.Set(reqPreviewDisplay, previewResult{version, []string{err.Error()}, 0, ""})1863- } else {1864- reaps = 21859+ if err == nil {1860+ reapChan := make(chan bool)1861 lineChan := make(chan eachLine)1862 // Goroutine 1 reads process output1863 go func() {1864 for {4 unmodified lines1869 }1870 }1871 eofChan <- true1872 }()1873+1874 // Goroutine 2 periodically requests rendering1875 go func(version int64) {1876 lines := []string{}1877 spinner := makeSpinner(t.unicode)33 unmodified lines1911 }1912 ticker.Stop()1913 reapChan <- true1914 }(version)1918- }1919- // Goroutine 3 is responsible for cancelling running preview command1920- go func(version int64) {1921- timer := time.NewTimer(previewDelayed)1922- Loop:1923- for {1924- select {1925- case <-timer.C:1926- t.reqBox.Set(reqPreviewDelayed, version)1927- case code := <-t.killChan:1928- if code != exitCancel {1929- util.KillCommand(cmd)1930- os.Exit(code)1931- } else {1932- timer := time.NewTimer(previewCancelWait)1933- select {1934- case <-timer.C:1915+1916+ // Goroutine 3 is responsible for cancelling running preview command1917+ go func(version int64) {1918+ timer := time.NewTimer(previewDelayed)1919+ Loop:1920+ for {1921+ select {1922+ case <-timer.C:1923+ t.reqBox.Set(reqPreviewDelayed, version)1924+ case code := <-t.killChan:1925+ if code != exitCancel {1926 util.KillCommand(cmd)1927+ os.Exit(code)1928+ } else {1929+ timer := time.NewTimer(previewCancelWait)1930+ select {1931+ case <-timer.C:1932+ util.KillCommand(cmd)1936- case <-finishChan:1933+ case <-finishChan:1934+ }1935+ timer.Stop()1936 }1938- timer.Stop()1937+ break Loop1938+ case <-finishChan:1939+ break Loop1940 }1940- break Loop1941- case <-finishChan:1942- break Loop1941 }1944- }1945- timer.Stop()1946- reapChan <- true1947- }(version)1948- <-eofChan1949- cmd.Wait() // NOTE: We should not call Wait before EOF1950- finishChan <- true1951- for i := 0; i < reaps; i++ {1942+ timer.Stop()1943+ reapChan <- true1944+ }(version)1945+1946+ <-eofChan // Goroutine 1 finished1947+ cmd.Wait() // NOTE: We should not call Wait before EOF1948+ finishChan <- true // Tell Goroutine 3 to stop1949+ <-reapChan // Goroutine 2 and 3 finished1950 <-reapChan1951+ } else {1952+ // Failed to start the command. Report the error immediately.1953+ t.reqBox.Set(reqPreviewDisplay, previewResult{version, []string{err.Error()}, 0, ""})1954 }1955+1956 cleanTemporaryFiles()1957 } else {1958 t.reqBox.Set(reqPreviewDisplay, previewResult{version, nil, 0, ""})1959 }627 unmodified lines