rename dump flag

put an error response body if json marshalling breaks.

detect and respond to http error codes in the client.
pull/1909/head
Joseph Rothrock 2015-03-18 14:10:36 -07:00
parent 91014def56
commit 21fd2e2662
3 changed files with 19 additions and 15 deletions

View File

@ -164,6 +164,9 @@ func (c *Client) Dump(db string) (io.ReadCloser, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp.StatusCode != http.StatusOK {
return resp.Body, fmt.Errorf("HTTP Protocol error %d", resp.StatusCode)
}
return resp.Body, nil return resp.Body, nil
} }

View File

@ -32,17 +32,17 @@ const (
) )
type CommandLine struct { type CommandLine struct {
Client *client.Client Client *client.Client
Line *liner.State Line *liner.State
Host string Host string
Port int Port int
Username string Username string
Password string Password string
Database string Database string
Version string Version string
Pretty bool // controls pretty print for json Pretty bool // controls pretty print for json
Format string // controls the output format. Valid values are json, csv, or column Format string // controls the output format. Valid values are json, csv, or column
Dump bool DumpTheDatabase bool
} }
func main() { func main() {
@ -55,7 +55,7 @@ func main() {
fs.StringVar(&c.Password, "password", c.Password, `password to connect to the server. Leaving blank will prompt for password (--password="")`) fs.StringVar(&c.Password, "password", c.Password, `password to connect to the server. Leaving blank will prompt for password (--password="")`)
fs.StringVar(&c.Database, "database", c.Database, "database to connect to the server.") fs.StringVar(&c.Database, "database", c.Database, "database to connect to the server.")
fs.StringVar(&c.Format, "output", default_format, "format specifies the format of the server responses: json, csv, or column") fs.StringVar(&c.Format, "output", default_format, "format specifies the format of the server responses: json, csv, or column")
fs.BoolVar(&c.Dump, "dump", false, "dump the contents of the given database to stdout") fs.BoolVar(&c.DumpTheDatabase, "dump-the-database", false, "dump the contents of the given database to stdout")
fs.Parse(os.Args[1:]) fs.Parse(os.Args[1:])
var promptForPassword bool var promptForPassword bool
@ -82,7 +82,7 @@ func main() {
c.connect("") c.connect("")
if c.Dump { if c.DumpTheDatabase {
c.dump() c.dump()
return return
} }
@ -212,7 +212,7 @@ func (c *CommandLine) connect(cmd string) {
fmt.Printf("Failed to connect to %s\n", c.Client.Addr()) fmt.Printf("Failed to connect to %s\n", c.Client.Addr())
} else { } else {
c.Version = v c.Version = v
if !c.Dump { if !c.DumpTheDatabase {
fmt.Printf("Connected to %s version %s\n", c.Client.Addr(), c.Version) fmt.Printf("Connected to %s version %s\n", c.Client.Addr(), c.Version)
} }
} }

View File

@ -295,7 +295,8 @@ func (h *Handler) serveDump(w http.ResponseWriter, r *http.Request, user *influx
buf, err := json.Marshal(&batch) buf, err := json.Marshal(&batch)
if err != nil { if err != nil {
httpError(w, "error with dump: "+err.Error(), pretty, http.StatusInternalServerError) w.Write([]byte("*** SERVER-SIDE ERROR. MISSING DATA ***"))
w.Write(delim)
return return
} }
w.Write(buf) w.Write(buf)