Skip to content

fix(cli): instantiate visitor class to resolve build error#828

Merged
mttrbrts merged 1 commit intoaccordproject:mainfrom
rockaxorb13:fix/cli-visitor-bug
Feb 25, 2026
Merged

fix(cli): instantiate visitor class to resolve build error#828
mttrbrts merged 1 commit intoaccordproject:mainfrom
rockaxorb13:fix/cli-visitor-bug

Conversation

@rockaxorb13
Copy link
Contributor

Summary

This PR fixes a critical bug in the cicero-cli compile command where the build would crash with TypeError: visitor.visit is not a function.

The issue stems from a breaking API change in the dependency @accordproject/concerto-codegen. The CLI was attempting to use a Class constructor as if it were an instantiated object. This PR updates the logic to correctly instantiate the visitor class before use.

Technical Details

The cicero-cli relies on concerto-codegen to retrieve visitor classes for generating output (e.g., Java, Go, JSONSchema).

  • Previous Behavior: CodeGen.formats[target] returned an instance of the visitor.
  • Current Behavior: CodeGen.formats[target] returns the Class constructor of the visitor.

The existing code in commands.js was attempting to call .visit() directly on the class constructor, resulting in the runtime error:
TypeError: visitor.visit is not a function

The Fix

Updated packages/cicero-cli/lib/commands.js to instantiate the class using the new keyword.

Before:

const visitor = CodeGen.formats[target];
// Error: 'visitor' is a Class, not an object.
template.getModelManager().accept(visitor, parameters);

After

const VisitorClass = CodeGen.formats[target];
// Fix: Instantiate the class first.
const visitor = new VisitorClass();
template.getModelManager().accept(visitor, parameters);

Verification

Ran npm test locally.

Before: 16 failing tests in @accordproject/cicero-cli.

After: All tests passed (45 passing)

Signed-off-by: Aadityavardhan Singh <singhrashmi018@gmail.com>
@mttrbrts mttrbrts merged commit 9d879c0 into accordproject:main Feb 25, 2026
6 of 7 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical runtime error in the cicero-cli compile command caused by a breaking API change in the @accordproject/concerto-codegen dependency. The dependency now returns class constructors instead of instantiated objects from CodeGen.formats.

Changes:

  • Updated compile function to instantiate the visitor class before use, resolving TypeError: visitor.visit is not a function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants