{"record":{"id":"33af6063bf82d67a","repo":"davila7/claude-code-templates","slug":"validate-must-be-implemented-by-subclass","errorCode":null,"errorMessage":"validate() must be implemented by subclass","messagePattern":"validate\\(\\) must be implemented by subclass","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli-tool/src/validation/BaseValidator.js","lineNumber":148,"sourceCode":"    const column = index - lineStart + 1;\n\n    return {\n      line: lineNumber,\n      column: column,\n      lineText: lineText.trim(),\n      position: `${lineNumber}:${column}`\n    };\n  }\n\n  /**\n   * Abstract method - must be implemented by subclasses\n   * @param {object} component - Component to validate\n   * @param {object} options - Validation options\n   * @returns {Promise<object>} Validation results\n   * @throws {Error} If not implemented\n   */\n  async validate(component, options = {}) {\n    throw new Error('validate() must be implemented by subclass');\n  }\n}\n\nmodule.exports = BaseValidator;\n","sourceCodeStart":130,"sourceCodeEnd":153,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/validation/BaseValidator.js#L130-L153","documentation":"Thrown by BaseValidator.validate() in cli-tool/src/validation/BaseValidator.js. BaseValidator is an abstract base class; its validate() is a placeholder that always throws, and every concrete validator (per component type) must override it. Hitting this error means a validator subclass was instantiated without implementing validate(), or the base class was used directly.","triggerScenarios":"Calling new BaseValidator().validate(...) or creating a subclass that forgets to define an async validate(component, options) method. Also reachable if a subclass defines validate as a non-method property or with a different name, so the inherited stub runs.","commonSituations":"Adding a new component-type validator and forgetting the validate() override; refactoring renaming validate to validateComponent; JavaScript silently allowing instantiation of the abstract class.","solutions":["Implement an async validate(component, options = {}) method in the subclass returning the standard result object","If you meant to run a real validation, instantiate the concrete validator for the component type instead of BaseValidator","Add a static assertion or JSDoc @abstract marker so the subclass is checked at definition time"],"exampleFix":"// before\nclass MyValidator extends BaseValidator {}\nawait new MyValidator().validate(component);\n\n// after\nclass MyValidator extends BaseValidator {\n  async validate(component, options = {}) {\n    // ...perform checks...\n    return { valid: true, errors: [], warnings: [] };\n  }\n}\nawait new MyValidator().validate(component);","handlingStrategy":"type-guard","validationCode":"if (validator instanceof BaseValidator && validator.constructor === BaseValidator) {\n  throw new Error('Do not instantiate BaseValidator directly');\n}","typeGuard":"function implementsValidate(v) {\n  return typeof v === 'object' && v !== null\n    && typeof v.validate === 'function'\n    && v.validate !== BaseValidator.prototype.validate; // not the stub\n}","tryCatchPattern":"try {\n  result = await validator.validate(component, options);\n} catch (e) {\n  if (/must be implemented by subclass/.test(e.message)) {\n    throw new Error(`${validator.constructor.name} does not implement validate() — implementation bug`);\n  }\n  throw e;\n}","preventionTips":["Implement validate(component, options) in every validator subclass","Check validator.validate !== BaseValidator.prototype.validate in a registration/startup sanity test","Mark BaseValidator.validate with @abstract JSDoc and cover subclasses with a unit test that calls validate()"],"tags":["abstract-class","subclass-contract","validation","oop"],"backgroundTag":"unimplemented-abstract-method","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}