{"record":{"id":"b525d09a3e926920","repo":"yamadashy/repomix","slug":"failed-to-prepare-language-name-message","errorCode":null,"errorMessage":"Failed to prepare language ${name}: ${message}","messagePattern":"Failed to prepare language (.+?): (.+?)","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/core/treeSitter/languageParser.ts","lineNumber":54,"sourceCode":"      // Create strategy instance lazily when first needed\n      // NOTE: Strategy instances are cached per language in this.loadedResources\n      // and shared across all files of the same language. This is safe because\n      // all current strategies are stateless and only use the parameters passed\n      // to their parseCapture method.\n      const strategy = config.createStrategy();\n\n      const resources: LanguageResources = {\n        lang: name,\n        parser,\n        query,\n        strategy,\n      };\n\n      this.loadedResources.set(name, resources);\n      return resources;\n    } catch (error) {\n      const message = error instanceof Error ? error.message : String(error);\n      throw new RepomixError(`Failed to prepare language ${name}: ${message}`);\n    }\n  }\n\n  private async getResources(name: SupportedLang): Promise<LanguageResources> {\n    if (!this.initialized) {\n      throw new RepomixError('LanguageParser is not initialized. Call init() first.');\n    }\n\n    const resources = this.loadedResources.get(name);\n    if (!resources) {\n      return this.prepareLang(name);\n    }\n    return resources;\n  }\n\n  public async getParserForLang(name: SupportedLang): Promise<Parser> {\n    const resources = await this.getResources(name);\n    return resources.parser;","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/treeSitter/languageParser.ts#L36-L72","documentation":"prepareLang's outer catch-all: any failure while loading the wasm grammar, creating the Parser, setting the language, or compiling the query is rethrown as 'Failed to prepare language <name>: <message>'. The original message is inlined so the root cause is visible.","triggerScenarios":"loadLanguage throws (missing/corrupt wasm), new Query() fails due to invalid query syntax for the grammar version, parser.setLanguage rejects an incompatible Language, or the config query is empty/malformed.","commonSituations":"Stale or mismatched tree-sitter wasm artifacts after upgrading tree-sitter; corrupted node_modules; a newly added query referencing nodes that don't exist in the grammar version.","solutions":["Read the inlined <message> for the root cause (wasm load vs query compile)","Reinstall dependencies (rm -rf node_modules && npm ci) to restore wasm grammars","Fix the language's query file so it matches the grammar's node names/version","If a wasm is corrupt, rebuild it (npm run language-* scripts) or re-download"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isRepomixError = (e: unknown): e is RepomixError => e instanceof RepomixError;","tryCatchPattern":"try {\n  await parser.init();\n  const res = await parser.getResources(lang);\n} catch (err) {\n  const msg = err instanceof Error ? err.message : String(err);\n  if (msg.includes('Failed to prepare language')) {\n    console.error(`tree-sitter setup failed for ${lang}: ${msg}`); // falls back to regex-based tokenization\n  } else throw err;\n}","preventionTips":["Reinstall node_modules after upgrading tree-sitter/web-tree-sitter","Validate query files against the grammar version in CI","Keep grammar wasm artifacts in lockstep with query syntax","Log the inner cause for faster triage"],"tags":["tree-sitter","wasm","initialization"],"backgroundTag":"parser-init-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}