go-delve/delve · error

%q is not a valid format

Error message

%q is not a valid format

What it means

ParseExamineMemoryArg parses options for the 'examine-memory' (x) command. The -fmt/-format flag accepts only formats present in fmtMapToPriFmt (hex, octal, decimal, bin/binary, etc.). Any other token after -fmt produces this error. It is a user input validation error, not a debugger state failure.

Source

Thrown at service/api/command.go:233

			if arg == "" {
				return nil, errors.New("expected argument after -fmt")
			}
			if arg == "raw" {
				out.RawOut = true
			} else {
				fmtMapToPriFmt := map[string]byte{
					"oct":         'o',
					"octal":       'o',
					"hex":         'x',
					"hexadecimal": 'x',
					"dec":         'd',
					"decimal":     'd',
					"bin":         'b',
					"binary":      'b',
				}
				out.Format, ok = fmtMapToPriFmt[arg]
				if !ok {
					return nil, fmt.Errorf("%q is not a valid format", arg)
				}
			}
		case "-count", "-len":
			arg := nextArg()
			if arg == "" {
				return nil, errors.New("expected argument after -count/-len")
			}
			var err error
			out.Count, err = strconv.ParseInt(arg, 0, 64)
			if err != nil || out.Count <= 0 {
				return nil, errors.New("count/len must be a positive integer")
			}
		case "-size":
			arg := nextArg()
			if arg == "" {
				return nil, errors.New("expected argument after -size")
			}
			var err error

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Use one of the accepted format names: hex, octal, decimal, bin, binary.
  2. Check service/api/command.go for the current fmtMapToPriFmt keys - use exactly those strings.
  3. Omit -fmt to use the default format.

Example fix

// before
examine-memory -fmt x 0xc000010000
// after
examine-memory -fmt hex 0xc000010000
Defensive patterns

Strategy: validation

Validate before calling

var validFormats = map[string]bool{"hex": true, "octal": true, "decimal": true, "bin": true, "binary": true}
if !validFormats(f) { return fmt.Errorf("unsupported format %q", f) } // check before passing -fmt

Try / catch

args, err := api.ParseExamineMemoryArg(argstr)
if err != nil {
	return fmt.Errorf("invalid examine-memory args: %v", err)
}

Prevention

When it happens

Trigger: Calling ParseExamineMemoryArg or the 'examine-memory' DAP command with e.g. '-fmt float64 0xc000010000' or '-format x addr' - 'x' and 'float64' are not keys in fmtMapToPriFmt.

Common situations: Using printf-style format letters ('x', 'd') instead of full names ('hex', 'decimal'); expecting arbitrary Go format verbs; copying syntax from gdb's x command.

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/45d21da936d84a73. Report an issue: GitHub.