microsoft/typescript-go · warning · Error

Cannot parse string enum value: ${goValue}

Error message

Cannot parse string enum value: ${goValue}

What it means

Tracing events are buffered in memory and flushed to <traceDir>/trace.json only when the buffer exceeds flushThreshold (256 KiB); maybeFlushLocked performs that AppendFile. Per the code's own contract, a flush failure is recorded in tr.flushErr and all subsequent writes become no-ops — the compiler keeps running and the error is only surfaced later from StopTracing. So seeing this error means trace output was silently truncated from the moment of the first failed flush onward.

Source

Thrown at Herebyfile.mjs:434

/**
 * Resolve a Go string-constant expression (e.g. `Prefix + "call"` or `"export="`)
 * into a quoted, JS-escaped TypeScript string literal. `replacements` maps bare
 * Go identifiers (such as a sentinel-prefix constant) to their literal value.
 * @param {string} goValue
 * @param {Record<string, string>} replacements
 * @returns {string}
 */
function parseGoStringValue(goValue, replacements) {
    let result = "";
    for (const part of goValue.split("+").map(p => p.trim())) {
        if (Object.prototype.hasOwnProperty.call(replacements, part)) {
            result += replacements[part];
            continue;
        }
        const stringMatch = part.match(/^"((?:[^"\\]|\\.)*)"$/);
        if (stringMatch === null) {
            throw new Error(`Cannot parse string enum value: ${goValue}`);
        }
        // Interpret Go escape sequences via JSON, then re-stringify below.
        result += JSON.parse(`"${stringMatch[1]}"`);
    }
    return JSON.stringify(result);
}

/**
 * @param {EnumDef} def
 * @returns {{ name: string, value: string }[]}
 */
function parseGoEnum(def) {
    const source = fs.readFileSync(def.goFile, "utf-8");
    const constBlockRegex = /const\s*\(([\s\S]*?)\n\)/g;

    for (const match of source.matchAll(constBlockRegex)) {
        const members = parseGoConstBlock(match[1], def).filter(member => !def.excludeMembers?.includes(member.name));
        if (members.length > 0) return topoSortMembers(members);

View on GitHub (pinned to 1bcfa18d79)

Solutions

  1. Free disk space or point traceDir at a volume with enough room, then re-run — the current session's trace is already incomplete.
  2. Ensure nothing deletes/locks the trace file while the session is live (exclude traceDir from cleanup jobs and artifact-upload hooks).
  3. Check permissions on traceDir and the trace file for the duration of the run (same user, writable).
  4. Treat a StopTracing error as 'trace possibly truncated': re-run tracing after fixing I/O rather than trusting the partial file.

Example fix

// before: error surfaces only at stop
if err := tr.StopTracing(); err != nil { // "failed to flush trace file: ..."
	log.Printf("trace incomplete: %v", err)
}

// after: pre-flight writability check before a long session
probe := filepath.Join(traceDir, ".probe")
if err := os.WriteFile(probe, nil, 0o644); err != nil {
	return fmt.Errorf("trace dir not writable: %w", err)
}
os.Remove(probe)
Defensive patterns

Strategy: try-catch

Try / catch

// flush failures are deferred; only StopTracing reveals them
if err := tr.StopTracing(); err != nil {
	if strings.Contains(err.Error(), "failed to flush trace file") {
		// trace is truncated from the first failed flush — discard and re-run
		log.Printf("trace truncated: %v; re-run after freeing disk", err)
	} else {
		return err
	}
}

Prevention

When it happens

Trigger: Any long tracing session that emits >256 KiB of events (large projects, heavy checkTypes phases) where AppendFile then fails: trace file deleted or truncated by an external process mid-session, permissions changed, disk full, or the FS handle invalidated (container/overlay teardown). The error originates at flush time but reaches the caller only when StopTracing returns it.

Common situations: Disk filling up during a full-project trace (trace files are large); a watcher/cleaner deleting the trace directory while tsgo runs; CI artifact collection moving files mid-run; tracing a monorepo where event volume crosses many flush thresholds.

Related errors


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/ffb1018281e498de. Report an issue: GitHub.