{"record":{"id":"3a558356eec2b8f8","repo":"microsoft/typescript-go","slug":"failed-to-write-trace-file-header-w","errorCode":null,"errorMessage":"failed to write trace file header: %w","messagePattern":"failed to write trace file header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tracing/tracing.go","lineNumber":182,"sourceCode":"\t}\n\ttr.traceStarted.Store(true)\n\n\t// Write the trace file header with metadata events\n\ttr.traceContent.WriteString(\"[\\n\")\n\n\t// Write metadata events (matching TypeScript's format)\n\tmetaTs := tr.timestamp()\n\ttr.metadataTS = metaTs\n\ttr.writeEvent(traceEvent{PID: 1, TID: mainThreadID, PH: \"M\", Cat: \"__metadata\", TS: metaTs, Name: \"process_name\", Args: map[string]any{\"name\": \"tsgo\"}})\n\ttr.traceContent.WriteString(\",\\n\")\n\ttr.writeEvent(traceEvent{PID: 1, TID: mainThreadID, PH: \"M\", Cat: \"__metadata\", TS: metaTs, Name: \"thread_name\", Args: map[string]any{\"name\": \"Main\"}})\n\ttr.traceContent.WriteString(\",\\n\")\n\ttr.writeEvent(traceEvent{PID: 1, TID: mainThreadID, PH: \"M\", Cat: \"disabled-by-default-devtools.timeline\", TS: metaTs, Name: \"TracingStartedInBrowser\"})\n\n\t// Truncate any existing trace file with the header so subsequent AppendFile\n\t// calls extend a clean file.\n\tif err := tr.fs.WriteFile(tr.tracePath, tr.traceContent.String()); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to write trace file header: %w\", err)\n\t}\n\ttr.traceContent.Reset()\n\n\treturn tr, nil\n}\n\n// timestamp returns the current timestamp in microseconds.\n// In deterministic mode it returns a monotonically increasing counter;\n// otherwise it returns the real elapsed wall-clock time since tracing started,\n// matching TypeScript's 1000 * timestamp() (microseconds).\nfunc (tr *Tracing) timestamp() float64 {\n\tif tr.deterministic {\n\t\ttr.timestampCounter++\n\t\treturn float64(tr.timestampCounter)\n\t}\n\treturn float64(time.Since(tr.startTime).Nanoseconds()) / 1000.0\n}\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/tracing/tracing.go#L164-L200","documentation":"Error \"failed to write trace file header: %w\" thrown in microsoft/typescript-go.","triggerScenarios":"Thrown at internal/tracing/tracing.go:182 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}