overleaf/overleaf · error · Error
FileData: toStats not implemented
Error message
FileData: toStats not implemented
What it means
toStats() returns a Record<string, number> of file statistics (e.g. byte/string lengths) and is another abstract stub on the FileData base class. Every concrete subclass must override it; hitting the stub means the receiver has no stats implementation. Throwing keeps stats consumers from reading meaningless defaults like 0.
Source
Thrown at libraries/overleaf-editor-core/lib/file_data/index.js:88
return new LazyStringFileData(
blob.getHash(),
rangesBlob?.getHash(),
stringLength
)
}
/**
* @returns {RawFileData}
*/
toRaw() {
throw new Error('FileData: toRaw not implemented')
}
/**
* @returns {Record<string, number>}
*/
toStats() {
throw new Error('FileData: toStats not implemented')
}
/**
* @see File#getHash
* @return {string | null | undefined}
*/
getHash() {
return null
}
/**
* @see File#getHash
* @return {string | null | undefined}
*/
getRangesHash() {
return null
}View on GitHub (pinned to 28ad3b03b7)
Solutions
- Add a toStats() override to the offending subclass returning its numeric stats (e.g. {byteLength, stringLength}).
- Replace ad-hoc subclass instances with the library's concrete classes that already implement toStats.
- Update subclasses after upgrading overleaf-editor-core to satisfy any newly added abstract members.
Example fix
// before
class CustomFileData extends FileData {}
// after
class CustomFileData extends FileData {
toStats() {
return { byteLength: this.getByteLength() || 0 }
}
} Defensive patterns
Strategy: type-guard
Validate before calling
if (FileData.prototype.toStats === fileData.toStats) {
throw new Error(fileData.constructor.name + ' does not implement toStats')
} Type guard
const implementsToStats = (fd) => fd instanceof FileData && FileData.prototype.toStats !== fd.toStats
Try / catch
let stats
try {
stats = fileData.toStats()
} catch (err) {
if (err.message === 'FileData: toStats not implemented') {
stats = {}
} else {
throw err
}
} Prevention
- Override all abstract methods when extending FileData, not just the ones currently used.
- Re-run subclass test suites after upgrading overleaf-editor-core (new abstract methods may appear).
- Prefer composition over subclassing FileData for test doubles.
When it happens
Trigger: Calling toStats() on a bare new FileData() or on a custom subclass that overrides toRaw/edit but not toStats; invoking it through File wrapper methods on such an instance.
Common situations: Custom or test-double FileData subclasses; version drift where a new abstract method (toStats) was added and older subclasses in your codebase were not updated; directly instantiating the base class.
Understand the failure class
Background: "NotImplementedError: Subclasses should override this method" / "must be implemented" — abstract method errors explained — this error's family across 40 libraries.
Related errors
- FileData: toRaw not implemented
- toEager not implemented for ${JSON.stringify(this)}
- toLazy not implemented for ${JSON.stringify(this)}
- toHollow not implemented for ${JSON.stringify(this)}
- getTrackedChanges not implemented for ${JSON.stringify(this)
AI-assisted analysis of overleaf/overleaf@28ad3b03b7 (2026-09-03).
Data as JSON: /api/errors/f53a014b13113adb.
Report an issue: GitHub.