{"record":{"id":"187f940893557fc7","repo":"microsoft/typescript-go","slug":"failed-to-extract-version-from-version-go","errorCode":null,"errorMessage":"Failed to extract version from version.go","messagePattern":"Failed to extract version from version\\.go","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Herebyfile.mjs","lineNumber":1217,"sourceCode":"        try {\r\n            deferred.resolve(this._action());\r\n        }\r\n        catch (e) {\r\n            deferred.reject(e);\r\n        }\r\n    }\r\n}\r\n\r\nconst getVersion = memoize(() => {\r\n    if (nativePreviewReleaseVersion) {\r\n        return nativePreviewReleaseVersion;\r\n    }\r\n\r\n    const f = fs.readFileSync(\"./internal/core/version.go\", \"utf8\");\r\n\r\n    const match = f.match(/var version\\s*=\\s*\"(\\d+\\.\\d+\\.\\d+)(-[^\"]+)?\"/);\r\n    if (!match) {\r\n        throw new Error(\"Failed to extract version from version.go\");\r\n    }\r\n\r\n    let version = match[1];\r\n    if (options.setPrerelease) {\r\n        version += `-${options.setPrerelease}`;\r\n    }\r\n    else if (match[2]) {\r\n        version += match[2];\r\n    }\r\n\r\n    return version;\r\n});\r\n\r\nfunction getPublishTag() {\r\n    if (publishAsTypescript) {\r\n        const version = getVersion();\r\n        if (!version) {\r\n            throw new Error(\"Publishing as 'typescript' requires a version before selecting an npm tag.\");\r","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/Herebyfile.mjs#L1199-L1235","documentation":"Per-checker type dumps are written by typeTracer.DumpTypes: it builds a JSON array where each traced type is serialized with json.MarshalWrite into a strings.Builder, with the type's line number matching its type ID. This error wraps a marshal failure for the specific typ.Id() that failed, after which the whole types_N.json for that checker is abandoned (StopTracing wraps it further as 'failed to dump types for checker %d'). The most common real cause is an unencodable value inside a type descriptor — e.g. a NaN/Inf float, or a value type the JSON shim rejects.","triggerScenarios":"StopTracing (which calls tracer.DumpTypes per checker) when buildTypeDescriptor produces a descriptor containing a value the marshaller refuses: NaN/±Inf floats from type display data, func/chan values, cycles not normalized by recursionIdentityMap, or a custom JSON shim (json.MarshalWrite from the project's json package) rejecting a shape it doesn't support.","commonSituations":"Tracing checkers that observed exotic types (arithmetic producing NaN in symbol displays, very deep/generic recursion); swapping or version-skewing the project's custom JSON encoder; changes to buildTypeDescriptor adding raw checker values that encoding/json would reject.","solutions":["Reproduce with the same --trace flags and inspect the reported type ID (message includes it) using the checker's traced type list to find the offending value.","Sanitize descriptor values in buildTypeDescriptor: convert NaN/Inf floats to strings or omit them; keep only encodable types (strings, numbers, bools, maps, slices).","If using a custom JSON shim, test json.MarshalWrite against the failing descriptor directly and fix the shim (or fall back to encoding/json).","Report upstream with the minimal repro — type-dependent marshal failures usually indicate a descriptor-field bug."],"exampleFix":"// before: raw float that can be NaN leaks into the descriptor\nargs[\"value\"] = f\n\n// after: keep descriptors JSON-safe\nif math.IsNaN(f) || math.IsInf(f, 0) {\n\targs[\"value\"] = fmt.Sprintf(\"%v\", f)\n} else {\n\targs[\"value\"] = f\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := tr.StopTracing(); err != nil {\n\tif strings.Contains(err.Error(), \"failed to marshal type\") {\n\t\t// message includes the failing type ID; timing trace may still be usable,\n\t\t// but types_%d.json for that checker is incomplete — report upstream with repro\n\t\tlog.Printf(\"type serialization failed: %v\", err)\n\t}\n}","preventionTips":["When extending buildTypeDescriptor, restrict values to strings/numbers/bools/maps/slices.","Never pass NaN/Inf floats into descriptors; format them as strings.","Unit-test DumpTypes over traced types after changing descriptor shapes or the JSON shim.","Use the reported type ID from the message to isolate the offending type in repros."],"tags":["tracing","json","type-checker","serialization"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}