{"record":{"id":"7ab20247fa9d573d","repo":"mikefarah/yq","slug":"panic-err-on-parseint64-failure-while-sorting-i","errorCode":null,"errorMessage":"panic(err) on parseInt64 failure while sorting !!int values","messagePattern":"panic\\(err\\) on parseInt64 failure while sorting !!int values","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/yqlib/operator_sort.go","lineNumber":163,"sourceCode":"\t\t\tlog.Warningf(\"Could not parse time %v with layout %v for sort, sorting by string instead: %v\", lhs.Value, layout, err)\n\t\t\treturn strings.Compare(lhs.Value, rhs.Value)\n\t\t}\n\t\trhsTime, err := parseDateTime(layout, rhs.Value)\n\t\tif err != nil {\n\t\t\tlog.Warningf(\"Could not parse time %v with layout %v for sort, sorting by string instead: %v\", rhs.Value, layout, err)\n\t\t\treturn strings.Compare(lhs.Value, rhs.Value)\n\t\t}\n\t\tif lhsTime.Equal(rhsTime) {\n\t\t\treturn 0\n\t\t} else if lhsTime.Before(rhsTime) {\n\t\t\treturn -1\n\t\t}\n\n\t\treturn 1\n\t} else if lhsTag == \"!!int\" && rhsTag == \"!!int\" {\n\t\t_, lhsNum, err := parseInt64(lhs.Value)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\t_, rhsNum, err := parseInt64(rhs.Value)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tif lhsNum < rhsNum {\n\t\t\treturn -1\n\t\t} else if lhsNum > rhsNum {\n\t\t\treturn 1\n\t\t}\n\t\treturn 0\n\t} else if (lhsTag == \"!!int\" || lhsTag == \"!!float\") && (rhsTag == \"!!int\" || rhsTag == \"!!float\") {\n\t\tlhsNum, err := strconv.ParseFloat(lhs.Value, 64)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\trhsNum, err := strconv.ParseFloat(rhs.Value, 64)\n\t\tif err != nil {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_sort.go#L145-L181","documentation":"The sort operator's compare function panics when sort_by/sortKeys encounters two nodes both tagged !!int whose string value cannot be parsed as a 64-bit integer (parseInt64 in operator_sort.go:161-167). Rather than falling back to string comparison like the datetime branch does, it panics inside sort.Less, crashing the whole process. The !!int tag can be present on values that are not machine-parseable int64 (e.g. values tagged by a decoder or custom type tags), so the tag check is an unreliable guard.","triggerScenarios":"Running sort or sort_by (e.g. `yq 'sort_by(.key)'`) where at least two elements in the array are tagged !!int but their .Value string is not a valid int64: values exceeding int64 range (e.g. 99999999999999999999), strings like '1_000' or '0x1F' that were tagged !!int by an input format decoder, or nodes whose tags were forced with `tag: !!int`.","commonSituations":"Sorting arrays parsed from JSON/YAML containing very large integers (IDs, snowflakes, IPv4-as-int) that overflow int64; data re-tagged via yq's tag operator; CSV/properties inputs where everything is string but tags were coerced; sorting mixed-size numbers across architectures.","solutions":["Inspect the array being sorted with `yq '.[] | tag'` and find values tagged !!int that are not plain decimal int64 literals.","Correct the offending data at the source, or coerce to float/string before sorting: `sort_by(.val | tag=\"!!str\")` or `sort_by(.val | tonumber)` style coercion.","Pre-filter or fix oversized values: convert to !!float so the ParseFloat branch is used, or to !!str for lexicographic sorting.","If this is a bug in your data pipeline (bad tag assignment), fix the decoder/expression that forces the !!int tag.","Upgrade yq: newer versions may gracefully fall back to string comparison on parse failure, as already done for datetimes."],"exampleFix":"# before\nyq 'sort_by(.id)' data.yaml   # panics: .id = 99999999999999999999 tagged !!int\n\n# after\nyq 'sort_by(.id | from_yaml | tag=\"!!str\")' data.yaml\n# or fix the data\nyq '.[] |= (.id | tag=\"!!float\")' data.yaml | yq 'sort_by(.id)'","handlingStrategy":"validation","validationCode":"# validate all !!int values parse as int64 before sorting\nyq '.[] | select(tag == \"!!int\") | select(test(\"^-?[0-9]+$\") | not) ' data.yaml\n# empty output => safe to sort","typeGuard":"// Go: guard before compare\nfunc isParseableInt64(s string) bool {\n    _, err := strconv.ParseInt(s, 10, 64)\n    return err == nil\n}","tryCatchPattern":"// yqlib hosts: recover the sort panic\nfunc safeSort() (err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"sort panic: %v\", r) } }()\n    // ... run yq sort_by ...\n    return nil\n}","preventionTips":["Check numeric tags with `tag` operator before sort_by on untrusted data","Avoid forcing !!int tags onto large or exotic literals; use !!float or !!str","Normalize YAML 1.1 hex/underscore integers to decimal before sorting","Wrap embedded yqlib calls in recover() since sort panics cannot be returned as errors"],"tags":["panic","sorting","yq","int64-overflow"],"backgroundTag":"sort-numeric-parse-panic","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}