Skip to content

Refactor duplicated error class definitions in task-runner#124

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/refactor-duplicated-code
Draft

Refactor duplicated error class definitions in task-runner#124
Copilot wants to merge 3 commits into
mainfrom
copilot/refactor-duplicated-code

Conversation

Copilot AI commented Feb 5, 2026

Copy link
Copy Markdown

Three error classes in validators.js had identical implementations differing only in their name property.

Changes

  • Introduced createErrorClass() factory function to generate error classes with consistent validation behavior
  • Refactored StateError, UnknownDependencyError, and UnknownTaskError to use the factory
  • Preserved DependencyCycleError as a standalone class due to its additional cyclePath property

Before:

StateError: class StateError extends Error {
  constructor(message) {
    ow(message, ow.string);
    super(message);
    this.name = 'StateError';
  }
},
// ... repeated for UnknownDependencyError, UnknownTaskError

After:

function createErrorClass(name) {
  const ErrorClass = class extends Error {
    constructor(message) {
      ow(message, ow.string);
      super(message);
      this.name = name;
    }
  };
  Object.defineProperty(ErrorClass, 'name', { value: name });
  return ErrorClass;
}

// Usage
StateError: createErrorClass('StateError'),
UnknownDependencyError: createErrorClass('UnknownDependencyError'),
UnknownTaskError: createErrorClass('UnknownTaskError'),

Reduces ~27 lines of duplicated code to a single reusable factory function.

Original prompt

Find and refactor duplicated code.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 5, 2026 01:57
Co-authored-by: Goo78 <163220761+Goo78@users.noreply.github.com>
Co-authored-by: Goo78 <163220761+Goo78@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor duplicated error class definitions in task-runner Feb 5, 2026
Copilot AI requested a review from Goo78 February 5, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants