{"record":{"id":"564176cc9658d6f8","repo":"neoclide/coc.nvim","slug":"name-and-docomplete-required-for-createsource","errorCode":null,"errorMessage":"name and doComplete required for createSource","messagePattern":"name and doComplete required for createSource","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/completion/sources.ts","lineNumber":396,"sourceCode":"        disabled: !item.enable\n      })\n    }\n    return stats\n  }\n\n  private onDocumentEnter(bufnr: number): void {\n    let { sources } = this\n    for (let s of sources) {\n      if (s.enable && Is.func(s.onEnter)) {\n        s.onEnter(bufnr)\n      }\n    }\n  }\n\n  public createSource(config: SourceConfig): Disposable {\n    if (typeof config.name !== 'string' || typeof config.doComplete !== 'function') {\n      logger.error(`Bad config for createSource:`, config)\n      throw new TypeError(`name and doComplete required for createSource`)\n    }\n    let source = new Source(Object.assign({ sourceType: SourceType.Service } as any, config))\n    return this.addSource(source)\n  }\n  /**\n   * @internal\n   */\n\n  public dispose(): void {\n    disposeAll(this.disposables)\n  }\n}\n\nexport function logError(err: any): void {\n  logger.error('Error on source create', err)\n}\n\nexport function getSourceType(sourceType: SourceType): string {","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/completion/sources.ts#L378-L414","documentation":"The sources registry's createSource validates its configuration: it requires a string 'name' and a function 'doComplete'. Passing a malformed config is a programming error and throws a TypeError instead of registering a half-working source.","triggerScenarios":"Calling coc.sources.createSource({}) or with a config object where doComplete is a non-function (e.g. a promise result, undefined after bad import, or name accidentally overwritten).","commonSituations":"Extension authors building source configs dynamically and omitting fields; refactors that renamed doComplete in a custom source but not in the config passed to createSource.","solutions":["Pass an object with both name (string) and doComplete (function)","Fix the config construction so doComplete is not undefined","Check the config object logged by coc before createSource (it logs 'Bad config for createSource')"],"exampleFix":"// before\nsources.createSource({ name: 'mytag' })\n// after\nsources.createSource({ name: 'mytag', doComplete: async (opt) => ({ items: [] }), triggerPatterns: [] })","handlingStrategy":"validation","validationCode":"// validate config before createSource\nconst ok = typeof cfg?.name === 'string' && typeof cfg?.doComplete === 'function'\nif (!ok) throw new TypeError('source config needs name:string and doComplete:function')","typeGuard":"const isSourceConfig = (c): c is SourceConfig =>\n  !!c && typeof c.name === 'string' && typeof c.doComplete === 'function'","tryCatchPattern":"try {\n  sources.createSource(config)\n} catch (e) {\n  if (e instanceof TypeError) logger.error('bad source config', config)\n  else throw e\n}","preventionTips":["Type configs as SourceConfig so TypeScript catches missing fields","Never build source configs with possibly-undefined function fields","Read the logged 'Bad config for createSource' object when debugging"],"tags":["completion","validation","api-misuse","typescript"],"backgroundTag":"invalid-argument","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}