{"record":{"id":"72ff08b6d3591028","repo":"overleaf/overleaf","slug":"filedata-toraw-not-implemented","errorCode":null,"errorMessage":"FileData: toRaw not implemented","messagePattern":"FileData: toRaw not implemented","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libraries/overleaf-editor-core/lib/file_data/index.js","lineNumber":81,"sourceCode":"   */\n  static createLazyFromBlobs(blob, rangesBlob) {\n    assert.instance(blob, Blob, 'FileData: bad blob')\n    const stringLength = blob.getStringLength()\n    if (stringLength == null) {\n      return new BinaryFileData(blob.getHash(), blob.getByteLength())\n    }\n    return new LazyStringFileData(\n      blob.getHash(),\n      rangesBlob?.getHash(),\n      stringLength\n    )\n  }\n\n  /**\n   * @returns {RawFileData}\n   */\n  toRaw() {\n    throw new Error('FileData: toRaw not implemented')\n  }\n\n  /**\n   * @returns {Record<string, number>}\n   */\n  toStats() {\n    throw new Error('FileData: toStats not implemented')\n  }\n\n  /**\n   * @see File#getHash\n   * @return {string | null | undefined}\n   */\n\n  getHash() {\n    return null\n  }\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/overleaf/overleaf/blob/28ad3b03b71cb4311decdcb55c36b33ec10d72db/libraries/overleaf-editor-core/lib/file_data/index.js#L63-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nclass CustomFileData extends FileData {}\n// after\nclass CustomFileData extends FileData {\n  toRaw() {\n    return { content: this.getContent() }\n  }\n}","handlingStrategy":"type-guard","validationCode":"if (fileData.constructor === FileData) throw new Error('cannot serialize abstract FileData')\nif (typeof fileData.toRaw !== 'function' || FileData.prototype.toRaw === fileData.toRaw) {\n  throw new Error('subclass missing toRaw override')\n}","typeGuard":"const hasOwnToRaw = (fd) =>\n  fd instanceof FileData && FileData.prototype.toRaw !== fd.toRaw","tryCatchPattern":"let raw\ntry {\n  raw = fileData.toRaw()\n} catch (err) {\n  if (err.message === 'FileData: toRaw not implemented') {\n    throw new Error('cannot serialize ' + fileData.constructor.name + ': toRaw missing')\n  }\n  throw err\n}","preventionTips":["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."],"tags":["abstract-method","subclassing","overleaf-editor-core"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"28ad3b03b71cb4311decdcb55c36b33ec10d72db","analyzedAt":"2026-09-03T02:10:22.807Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}