{"record":{"id":"d539e0470fd4d869","repo":"go-delve/delve","slug":"expected-argument-after-fmt","errorCode":null,"errorMessage":"expected argument after -fmt","messagePattern":"expected argument after -fmt","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/api/command.go","lineNumber":216,"sourceCode":"\t\t\targ := args[0]\n\t\t\targs = args[1:]\n\t\t\tif arg != \"\" {\n\t\t\t\treturn arg\n\t\t\t}\n\t\t}\n\t\treturn \"\"\n\t}\n\nloop:\n\tfor {\n\t\tswitch cmd := nextArg(); cmd {\n\t\tcase \"\":\n\t\t\t// no more arguments\n\t\t\tbreak loop\n\t\tcase \"-fmt\":\n\t\t\targ := nextArg()\n\t\t\tif arg == \"\" {\n\t\t\t\treturn nil, errors.New(\"expected argument after -fmt\")\n\t\t\t}\n\t\t\tif arg == \"raw\" {\n\t\t\t\tout.RawOut = true\n\t\t\t} else {\n\t\t\t\tfmtMapToPriFmt := map[string]byte{\n\t\t\t\t\t\"oct\":         'o',\n\t\t\t\t\t\"octal\":       'o',\n\t\t\t\t\t\"hex\":         'x',\n\t\t\t\t\t\"hexadecimal\": 'x',\n\t\t\t\t\t\"dec\":         'd',\n\t\t\t\t\t\"decimal\":     'd',\n\t\t\t\t\t\"bin\":         'b',\n\t\t\t\t\t\"binary\":      'b',\n\t\t\t\t}\n\t\t\t\tout.Format, ok = fmtMapToPriFmt[arg]\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"%q is not a valid format\", arg)\n\t\t\t\t}","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/api/command.go#L198-L234","documentation":"ParseExamineMemoryArg parses arguments of the `examinemem`/`x` command. The -fmt flag requires a following format argument; when nextArg() returns an empty string (flag is last or followed by nothing), parsing fails with 'expected argument after -fmt'. The format may be 'raw' or a printf-style code (oct, x, bin, etc.).","triggerScenarios":"Calling `x -fmt 0x...` where the address follows immediately without a format value, or invoking the API ParseExamineMemoryArg with args ending in \"-fmt\". Also when an empty variable is expanded after -fmt so nextArg() yields \"\".","commonSituations":"Users forgetting the format code (`x -fmt 0xc000010000` instead of `x -fmt x 0xc000010000`); shell scripts with unset format variables; IDE/command builders appending flags conditionally and leaving -fmt dangling.","solutions":["Supply a format after -fmt: x -fmt x 0xc00010000 (hex) or x -fmt raw ... for raw output","Valid formats: oct, x, bin, and other printf-style codes; use 'raw' for unformatted bytes","Ensure any variable providing the format is non-empty before composing the command"],"exampleFix":"// before\nout, err := api.ParseExamineMemoryArg([]string{\"-fmt\", \"0xc000010000\"})\n\n// after\nout, err := api.ParseExamineMemoryArg([]string{\"-fmt\", \"x\", \"0xc000010000\"})","handlingStrategy":"validation","validationCode":"# compose and sanity-check args before calling ParseExamineMemoryArg\nargs := []string{\"-fmt\", \"x\", \"0xc000010000\"}\nfor i, a := range args {\n    if a == \"-fmt\" && (i+1 >= len(args) || args[i+1] == \"\") {\n        panic(\"-fmt requires raw or a printf-style format\")\n    }\n}","typeGuard":"func flagHasArg(args []string, flag string) bool {\n    for i, a := range args {\n        if a == flag {\n            return i+1 < len(args) && args[i+1] != \"\"\n        }\n    }\n    return true // flag absent\n}","tryCatchPattern":null,"preventionTips":["Order matters: put the format immediately after -fmt, then the address (x -fmt x ADDR)","Remember the valid values: 'raw' or codes like oct, x, bin","In command builders, never append -fmt without its value in the same step"],"tags":["cli","parsing","examine-memory"],"backgroundTag":"missing-flag-argument","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}