diff --git a/command/agent/http.go b/command/agent/http.go index ac76dedc7bc..37371f9350b 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -709,13 +709,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 945c0abf59e..9409c08b665 100644 --- a/command/operator_debug_test.go +++ b/command/operator_debug_test.go @@ -56,6 +56,7 @@ func runTestCases(t *testing.T, cases testCases) { require.Equalf(t, code, c.expectedCode, "expected exit code %d, got: %d: %s", c.expectedCode, code, outerr) for _, expectedOutput := range c.expectedOutputs { require.Contains(t, out, expectedOutput, "expected output %q, got %q", expectedOutput, out) + } require.Containsf(t, outerr, c.expectedError, "expected error %q, got %q", c.expectedError, outerr) })