diff --git a/command/agent/http.go b/command/agent/http.go index b8b523ea3d83..f17e1df5db98 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -763,13 +763,17 @@ func parseWait(resp http.ResponseWriter, req *http.Request, b *structs.QueryOpti func parseConsistency(resp http.ResponseWriter, req *http.Request, b *structs.QueryOptions) { query := req.URL.Query() if staleVal, ok := query["stale"]; ok { + if len(staleVal) == 0 || staleVal[0] == "" { + b.AllowStale = true + return + } staleQuery, err := strconv.ParseBool(staleVal[0]) if err != nil { resp.WriteHeader(400) - resp.Write([]byte(fmt.Sprintf("Expect `true` or `false` for `stale` query string parameter, got %s", staleVal[0]))) + _, _ = resp.Write([]byte(fmt.Sprintf("Expect `true` or `false` for `stale` query string parameter, got %s", staleVal[0]))) + return } - - b.AllowStale = staleQuery || staleVal[0] == "" + b.AllowStale = staleQuery } } diff --git a/command/operator_debug_test.go b/command/operator_debug_test.go index d986ac26a29f..25d4378d29df 100644 --- a/command/operator_debug_test.go +++ b/command/operator_debug_test.go @@ -50,7 +50,7 @@ func runTestCases(t *testing.T, cases testCases) { out := ui.OutputWriter.String() outerr := ui.ErrorWriter.String() - assert.Equalf(t, code, c.expectedCode, "did not get expected exit code") + assert.Equalf(t, c.expectedCode, code, "did not get expected exit code") if len(c.expectedOutputs) > 0 { if assert.NotEmpty(t, out, "command output was empty") {