overleaf/overleaf · error · Error
FileData: toRaw not implemented
Error message
FileData: toRaw not implemented
What it means
toRaw() is defined on the FileData base class as an abstract stub and must be overridden by every concrete subclass (StringFileData, BinaryFileData, etc.). It is only reachable when calling toRaw on the base FileData itself or on a subclass that forgot to implement it. The library throws instead of returning a wrong serialization.
Source
Thrown at libraries/overleaf-editor-core/lib/file_data/index.js:81
*/
static createLazyFromBlobs(blob, rangesBlob) {
assert.instance(blob, Blob, 'FileData: bad blob')
const stringLength = blob.getStringLength()
if (stringLength == null) {
return new BinaryFileData(blob.getHash(), blob.getByteLength())
}
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
}
View on GitHub (pinned to 28ad3b03b7)
Solutions
- Check the constructor name in the failing instance and override toRaw() in that subclass, returning the correct RawFileData shape.
- Ensure you are not instantiating FileData directly; use one of the concrete subclasses or the static fromRaw/createHollow factories.
- If the class genuinely lacks content, switch to Hollow* variants which implement their own toRaw.
Example fix
// before
class CustomFileData extends FileData {}
// after
class CustomFileData extends FileData {
toRaw() {
return { content: this.getContent() }
}
} Defensive patterns
Strategy: type-guard
Validate before calling
if (fileData.constructor === FileData) throw new Error('cannot serialize abstract FileData')
if (typeof fileData.toRaw !== 'function' || FileData.prototype.toRaw === fileData.toRaw) {
throw new Error('subclass missing toRaw override')
} Type guard
const hasOwnToRaw = (fd) => fd instanceof FileData && FileData.prototype.toRaw !== fd.toRaw
Try / catch
let raw
try {
raw = fileData.toRaw()
} catch (err) {
if (err.message === 'FileData: toRaw not implemented') {
throw new Error('cannot serialize ' + fileData.constructor.name + ': toRaw missing')
}
throw err
} Prevention
- Never instantiate FileData directly; use its factories or concrete subclasses.
- For subclasses, override every abstract stub (toRaw, toStats, edit, toEager, toLazy, toHollow, store, getComments, getTrackedChanges).
- Add a test asserting each custom subclass serializes via toRaw without throwing.
When it happens
Trigger: Instantiating FileData directly (new FileData()) and calling toRaw(); or defining a custom subclass extending FileData without overriding toRaw, then serializing via file.toRaw() / File#toRaw.
Common situations: Custom FileData subclass written for tests or a plugin that implements only some abstract methods; refactors that renamed a subclass method so the base stub is now hit; constructing the abstract base class by mistake.
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: toStats 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/72ff08b6d3591028.
Report an issue: GitHub.