{"record":{"id":"e2df5bab80ddff9b","repo":"hashicorp/nomad","slug":"must-provide-log-type-stdout-stderr","errorCode":null,"errorMessage":"must provide log type (stdout/stderr)","messagePattern":"must provide log type \\(stdout/stderr\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"client/fs_endpoint.go","lineNumber":36,"sourceCode":"\t\"syscall\"\n\t\"time\"\n\n\tmetrics \"github.com/hashicorp/go-metrics/compat\"\n\t\"github.com/hashicorp/go-msgpack/v2/codec\"\n\t\"github.com/hpcloud/tail/watch\"\n\n\t\"github.com/hashicorp/nomad/acl\"\n\t\"github.com/hashicorp/nomad/client/allocdir\"\n\tsframer \"github.com/hashicorp/nomad/client/lib/streamframer\"\n\tcstructs \"github.com/hashicorp/nomad/client/structs\"\n\t\"github.com/hashicorp/nomad/nomad/structs\"\n)\n\nvar (\n\tallocIDNotPresentErr = fmt.Errorf(\"must provide a valid alloc id\")\n\tpathNotPresentErr    = fmt.Errorf(\"must provide a file path\")\n\ttaskNotPresentErr    = fmt.Errorf(\"must provide task name\")\n\tlogTypeNotPresentErr = fmt.Errorf(\"must provide log type (stdout/stderr)\")\n\tinvalidOrigin        = fmt.Errorf(\"origin must be start or end\")\n)\n\nconst (\n\t// streamFramesBuffer is the number of stream frames that will be buffered\n\t// before back pressure is applied on the stream framer.\n\tstreamFramesBuffer = 32\n\n\t// streamFrameSize is the maximum number of bytes to send in a single frame\n\tstreamFrameSize = 64 * 1024\n\n\t// streamHeartbeatRate is the rate at which a heartbeat will occur to detect\n\t// a closed connection without sending any additional data\n\tstreamHeartbeatRate = 1 * time.Second\n\n\t// streamBatchWindow is the window in which file content is batched before\n\t// being flushed if the frame size has not been hit.\n\tstreamBatchWindow = 200 * time.Millisecond","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/fs_endpoint.go#L18-L54","documentation":"logTypeNotPresentErr is a sentinel error for log requests whose Type is neither \"stdout\" nor \"stderr\". The client maps this field onto a filename variant, so anything else is rejected. Returned with HTTP 400 Bad Request from the logs endpoints.","triggerScenarios":"Calling logs/Logs with a req.Type value outside {\"stdout\", \"stderr\"} — empty string, \"out\", \"1\", \"both\", etc.","commonSituations":"CLI/API callers using abbreviations like 'out' or numeric fd identifiers; template variables defaulting to empty; mixing up the parameter name (passing log level or file name where type is expected).","solutions":["Set the type parameter to exactly \"stdout\" or \"stderr\" (lowercase)","In code, normalize/validate the log type before the request: switch t { case \"stdout\", \"stderr\": ... default: reject }","If you need both streams, issue two requests rather than a combined value"],"exampleFix":"// before\nreq := &cstructs.FsLogsRequest{AllocID: id, Task: \"web\", Type: \"out\"}\n// after\nreq := &cstructs.FsLogsRequest{AllocID: id, Task: \"web\", Type: \"stdout\"}","handlingStrategy":"validation","validationCode":"switch logType {\ncase \"stdout\", \"stderr\":\n    // ok\ndefault:\n    return fmt.Errorf(\"log type must be exactly \\\"stdout\\\" or \\\"stderr\\\", got %q\", logType)\n}","typeGuard":"func isValidLogType(t string) bool {\n    return t == \"stdout\" || t == \"stderr\"\n}","tryCatchPattern":"r, err := client.AllocFS().Logs(alloc, task, \"\", false, logType, \"end\", 0, ctx.Done(), nil)\nif err != nil && strings.Contains(err.Error(), \"must provide log type\") {\n    log.Printf(\"bad log type %q, falling back to stdout\", logType)\n    return client.AllocFS().Logs(alloc, task, \"\", false, \"stdout\", \"end\", 0, ctx.Done(), nil)\n}","preventionTips":["Whitelist the two valid values at the CLI/UI layer instead of free-text input","Normalize case (strings.ToLower) before sending","Never use numeric fd labels or abbreviations; use the API's exact strings"],"tags":["api","validation","logs"],"backgroundTag":"invalid-argument-value","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"}