Merge pull request #6491 from influxdata/js-cli-infinite-loop

Fix the CLI not to enter an infinite loop when the liner has an error
pull/6410/head
Jonathan A. Sternberg 2016-04-28 09:36:35 -04:00
commit 6371134bfa
2 changed files with 14 additions and 8 deletions

View File

@ -43,8 +43,9 @@
- [#6462](https://github.com/influxdata/influxdb/pull/6462): Add safer locking to CreateFieldIfNotExists
- [#6361](https://github.com/influxdata/influxdb/pull/6361): Fix cluster/pool release of connection
- [#6470](https://github.com/influxdata/influxdb/pull/6470): Remove SHOW SERVERS & DROP SERVER support
- [#6477] (https://github.com/influxdata/influxdb/pull/6477): Don't catch SIGQUIT or SIGHUP signals.
- [#6468](https://github.com/influxdata/influxdb/issues/6468): Panic with truncated wal segments
- [#6477](https://github.com/influxdata/influxdb/pull/6477): Don't catch SIGQUIT or SIGHUP signals.
- [#6468](https://github.com/influxdata/influxdb/issues/6468): Panic with truncated wal segments
- [#6491](https://github.com/influxdata/influxdb/pull/6491): Fix the CLI not to enter an infinite loop when the liner has an error.
## v0.12.2 [2016-04-20]

View File

@ -11,7 +11,6 @@ import (
"net/url"
"os"
"os/signal"
"os/user"
"path/filepath"
"sort"
"strconv"
@ -168,10 +167,10 @@ func (c *CommandLine) Run() error {
c.Version()
usr, err := user.Current()
// Only load/write history if we can get the user
if err == nil {
c.historyFilePath = filepath.Join(usr.HomeDir, ".influx_history")
// Only load/write history if HOME environment variable is set.
if homeDir := os.Getenv("HOME"); homeDir != "" {
// Attempt to load the history file.
c.historyFilePath = filepath.Join(homeDir, ".influx_history")
if historyFile, err := os.Open(c.historyFilePath); err == nil {
c.Line.ReadHistory(historyFile)
historyFile.Close()
@ -179,6 +178,11 @@ func (c *CommandLine) Run() error {
}
// read from prompt until exit is run
return c.mainLoop()
}
// mainLoop runs the main prompt loop for the CLI.
func (c *CommandLine) mainLoop() error {
for {
select {
case <-c.osSignals:
@ -193,7 +197,8 @@ func (c *CommandLine) Run() error {
// Instead of die, register that someone exited the program gracefully
l = "exit"
} else if e != nil {
break
c.exit()
return e
}
if err := c.ParseCommand(l); err != ErrBlankCommand {
c.Line.AppendHistory(l)