From 21fd2e2662a4fb729f55d6c3cc123ed271d749b1 Mon Sep 17 00:00:00 2001 From: Joseph Rothrock Date: Wed, 18 Mar 2015 14:10:36 -0700 Subject: [PATCH] dump cmd rename dump flag put an error response body if json marshalling breaks. detect and respond to http error codes in the client. --- client/influxdb.go | 3 +++ cmd/influx/main.go | 28 ++++++++++++++-------------- httpd/handler.go | 3 ++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/client/influxdb.go b/client/influxdb.go index b4872f8ab2..e46a83f072 100644 --- a/client/influxdb.go +++ b/client/influxdb.go @@ -164,6 +164,9 @@ func (c *Client) Dump(db string) (io.ReadCloser, error) { if err != nil { return nil, err } + if resp.StatusCode != http.StatusOK { + return resp.Body, fmt.Errorf("HTTP Protocol error %d", resp.StatusCode) + } return resp.Body, nil } diff --git a/cmd/influx/main.go b/cmd/influx/main.go index 5ef8aa65d5..a095018fbb 100644 --- a/cmd/influx/main.go +++ b/cmd/influx/main.go @@ -32,17 +32,17 @@ const ( ) type CommandLine struct { - Client *client.Client - Line *liner.State - Host string - Port int - Username string - Password string - Database string - Version string - Pretty bool // controls pretty print for json - Format string // controls the output format. Valid values are json, csv, or column - Dump bool + Client *client.Client + Line *liner.State + Host string + Port int + Username string + Password string + Database string + Version string + Pretty bool // controls pretty print for json + Format string // controls the output format. Valid values are json, csv, or column + DumpTheDatabase bool } 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.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.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:]) var promptForPassword bool @@ -82,7 +82,7 @@ func main() { c.connect("") - if c.Dump { + if c.DumpTheDatabase { c.dump() return } @@ -212,7 +212,7 @@ func (c *CommandLine) connect(cmd string) { fmt.Printf("Failed to connect to %s\n", c.Client.Addr()) } else { c.Version = v - if !c.Dump { + if !c.DumpTheDatabase { fmt.Printf("Connected to %s version %s\n", c.Client.Addr(), c.Version) } } diff --git a/httpd/handler.go b/httpd/handler.go index 3b1687d238..00997e7a57 100644 --- a/httpd/handler.go +++ b/httpd/handler.go @@ -295,7 +295,8 @@ func (h *Handler) serveDump(w http.ResponseWriter, r *http.Request, user *influx buf, err := json.Marshal(&batch) 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 } w.Write(buf)