{"record":{"id":"9075d6fd1fdbe35b","repo":"go-delve/delve","slug":"string-too-long-for-comparison","errorCode":null,"errorMessage":"string too long for comparison","messagePattern":"string too long for comparison","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2629,"sourceCode":"\tcase reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:\n\t\treturn constantCompare(op, xv.Value, yv.Value)\n\tcase reflect.String:\n\t\tif xv.Len != yv.Len {\n\t\t\tswitch op {\n\t\t\tcase token.EQL:\n\t\t\t\treturn false, nil\n\t\t\tcase token.NEQ:\n\t\t\t\treturn true, nil\n\t\t\t}\n\t\t}\n\t\tif xv.Kind == reflect.String {\n\t\t\txv.loadValue(loadFullValueLongerStrings)\n\t\t}\n\t\tif yv.Kind == reflect.String {\n\t\t\tyv.loadValue(loadFullValueLongerStrings)\n\t\t}\n\t\tif int64(len(constant.StringVal(xv.Value))) != xv.Len || int64(len(constant.StringVal(yv.Value))) != yv.Len {\n\t\t\treturn false, errors.New(\"string too long for comparison\")\n\t\t}\n\t\treturn constantCompare(op, xv.Value, yv.Value)\n\t}\n\n\tif op != token.EQL && op != token.NEQ {\n\t\treturn false, fmt.Errorf(\"operator %s not defined on %s\", op.String(), xv.Kind.String())\n\t}\n\n\tvar eql bool\n\tvar err error\n\n\tif xv == nilVariable {\n\t\tswitch op {\n\t\tcase token.EQL:\n\t\t\treturn yv.isNil(), nil\n\t\tcase token.NEQ:\n\t\t\treturn !yv.isNil(), nil\n\t\t}","sourceCodeStart":2611,"sourceCodeEnd":2647,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2611-L2647","documentation":"When comparing two strings with ==, !=, <, etc., Delve must load the full string contents from the debugged process into constant.Value form. To bound memory usage it truncates very long strings during load; if either operand of a string comparison was truncated (loaded length differs from the string's true Len), Delve refuses to give a potentially wrong comparison result and throws this error.","triggerScenarios":"Evaluating a comparison of two string variables (e.g. 'print s1 == s2', 'print s == \"literal\"') where at least one string is longer than the configured MaxStringLen and got truncated during loadValue.","commonSituations":"Comparing large payloads, log lines, or buffers inside the debugger with default config; hitting the error because MaxStringLen (default 64 in some paths) is smaller than the strings being compared.","solutions":["Increase the string limit before comparing: in the CLI use config max-string-len <n> (e.g. 'config max-string-len 4096'), or set cfg.MaxStringLen in API/LoadConfig usage","Compare lengths/shorter substrings instead: 'print len(s1) == len(s2)'","Compare string pointers/addresses if identity, not content, matters","For RPC clients, pass a larger MaxStringLen in the LoadConfig used for EvalExpression"],"exampleFix":"// before (dlv CLI)\n(dlv) print s == expected   // strings > default limit -> error\n\n// after\n(dlv) config max-string-len 8192\n(dlv) print s == expected","handlingStrategy":"validation","validationCode":"// before comparing strings in dlv\n(dlv) print len(s1)\n(dlv) print len(s2)\n// if either length exceeds max-string-len, raise it first:\n(dlv) config max-string-len 8192","typeGuard":"func comparableStrings(s1, s2 string, maxLen int) bool {\n    return len(s1) <= maxLen && len(s2) <= maxLen\n}","tryCatchPattern":"// RPC client pattern\nval, err := client.EvalVariable(scope, \"s1 == s2\", cfg)\nif err != nil && strings.Contains(err.Error(), \"string too long for comparison\") {\n    cfg.MaxStringLen *= 4\n    val, err = client.EvalVariable(scope, \"s1 == s2\", cfg)\n}","preventionTips":["Set 'config max-string-len' generously at session start when comparing strings","Compare lengths or short substrings instead of whole long strings","Keep LoadConfig.MaxStringLen aligned with the data sizes you debug","Prefer breakpoints over string equality expressions for very large payloads"],"tags":["go","debugger","string-comparison","truncation"],"backgroundTag":"string-truncated-for-comparison","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}