{"record":{"id":"840bd4fa6a445675","repo":"hashicorp/nomad","slug":"error-parsing-limit-v","errorCode":null,"errorMessage":"error parsing limit: %v","messagePattern":"error parsing limit: (.+?)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"command/agent/fs_endpoint.go","lineNumber":157,"sourceCode":"\tvar err error\n\n\tq := req.URL.Query()\n\n\tif allocID = strings.TrimPrefix(req.URL.Path, \"/v1/client/fs/readat/\"); allocID == \"\" {\n\t\treturn nil, allocIDNotPresentErr\n\t}\n\tif path = q.Get(\"path\"); path == \"\" {\n\t\treturn nil, fileNameNotPresentErr\n\t}\n\n\tif offset, err = strconv.ParseInt(q.Get(\"offset\"), 10, 64); err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing offset: %v\", err)\n\t}\n\n\t// Parse the limit\n\tif limitStr := q.Get(\"limit\"); limitStr != \"\" {\n\t\tif limit, err = strconv.ParseInt(limitStr, 10, 64); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error parsing limit: %v\", err)\n\t\t}\n\t}\n\n\t// Create the request arguments\n\tfsReq := &cstructs.FsStreamRequest{\n\t\tAllocID:   allocID,\n\t\tPath:      path,\n\t\tOffset:    offset,\n\t\tOrigin:    \"start\",\n\t\tLimit:     limit,\n\t\tPlainText: true,\n\t}\n\ts.parse(resp, req, &fsReq.QueryOptions.Region, &fsReq.QueryOptions)\n\n\t// Make the request\n\treturn s.fsStreamImpl(resp, req, \"FileSystem.Stream\", fsReq, fsReq.AllocID)\n}\n","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/fs_endpoint.go#L139-L175","documentation":"This error is returned by the agent's FileReadAt HTTP endpoint (command/agent/fs_endpoint.go:157) when the `limit` query parameter is present but cannot be parsed as a base-10 int64 via strconv.ParseInt. The limit caps how many bytes of file content are read. It wraps the underlying strconv error and rejects the request before the filesystem RPC is made.","triggerScenarios":"Calling GET /v1/client/fs/readat?alloc_id=<id>&path=<path>&limit=<v> where v is non-empty and not a plain int64: limit=abc, limit=1.5, limit=1e6, limit=10KB, or a value exceeding int64 range.","commonSituations":"Hand-built curl requests with unit suffixes; SDKs stringifying floats or computed sizes; shell variables expanding empty/whitespace; JSON number formatting like 1e6 leaking into query strings.","solutions":["Pass limit as a plain base-10 integer string, e.g. limit=32768 (no decimals, units, or exponents).","Validate the value with strconv.ParseInt(s, 10, 64) client-side before sending.","Omit the parameter entirely — it is only parsed when non-empty.","Clamp computed byte counts to math.MaxInt64 before formatting."],"exampleFix":"// before\ncurl \"http://localhost:4646/v1/client/fs/readat?alloc_id=abc&path=/logs/app.log&limit=1.5MB\"\n// after\ncurl \"http://localhost:4646/v1/client/fs/readat?alloc_id=abc&path=/logs/app.log&limit=1500000\"","handlingStrategy":"validation","validationCode":"limit := q.Get(\"limit\")\nif limit != \"\" {\n    if _, err := strconv.ParseInt(limit, 10, 64); err != nil {\n        return fmt.Errorf(\"invalid limit %q: must be a base-10 int64\", limit)\n    }\n}","typeGuard":"func validLimit(s string) bool {\n    if s == \"\" { return true }\n    _, err := strconv.ParseInt(s, 10, 64)\n    return err == nil\n}","tryCatchPattern":"res, err := fs.ReadAt(allocID, path, offset, limit)\nif err != nil {\n    if strings.Contains(err.Error(), \"error parsing limit\") {\n        // fall back: omit the limit parameter\n        res, err = fs.ReadAt(allocID, path, offset, \"\")\n    }\n}","preventionTips":["Format limits with strconv.FormatInt, never float formatting.","Validate query params with ParseInt before sending.","Omit empty optional parameters instead of sending empty strings.","Clamp computed byte counts to math.MaxInt64."],"tags":["http-api","query-params","parsing","nomad"],"backgroundTag":"invalid-query-parameter","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}