Troubleshooting

Last updated:

Troubleshooting

Common issues and solutions when working with Cerebro.

Command Not Found

Problem: CLI reports "Command not found" for existing command

$ my-cli build
Error: Command "build" not found

Solutions:

  1. Verify command is registered:
cli.addCommand({
  name: "build",
  execute: ({ logger }) => {
    logger.log("Building...");
  },
});
  1. Check for typos in command name
  2. Check nested command syntax:
$ my-cli db migrate    # Correct
$ my-cli db-migrate    # Wrong

Option Validation Errors

Problem: Required option errors

$ my-cli deploy
Error: Required option --environment is missing

Solution: Provide the required option:

$ my-cli deploy --environment production

Or make it optional with a default value:

{
  name: "environment",
  type: String,
  defaultValue: "staging",  // No longer required
}

Conflicting Options Error

Problem: Using incompatible options together

$ my-cli test --watch --ci
Error: Options --watch and --ci conflict

Solution: Use only one of the conflicting options:

$ my-cli test --watch
# or
$ my-cli test --ci

Type Errors

Problem: TypeScript errors for toolbox extensions

cli.addCommand({
  execute: ({ myFeature }) => {
    // Error: Property 'myFeature' does not exist
  },
});

Solution: Declare the extension type:

declare global {
  namespace Cerebro {
    interface ExtensionOverrides {
      myFeature: {
        doSomething: () => void;
      };
    }
  }
}

Plugin Initialization Issues

Problem: Plugin not working in commands

cli.use(myPlugin());

cli.addCommand({
  execute: ({ myFeature }) => {
    // myFeature is undefined
  },
});

Solutions:

  1. Check plugin registration order (before commands)
  2. Verify plugin adds to toolbox:
const myPlugin = (): Plugin => ({
  name: "my-plugin",
  register: async ({ toolbox }) => {
    toolbox.myFeature = { doSomething: () => {} };
  },
});
  1. Check for plugin dependencies

Environment Variable Issues

Problem: Required environment variable not found

$ my-cli deploy
Error: Required environment variable API_KEY is missing

Solution: Set the environment variable:

$ API_KEY=secret123 my-cli deploy

Or use a .env file:

# .env
API_KEY=secret123
import "dotenv/config";
import { createCerebro } from "@visulima/cerebro";
// ...

Help Text Not Showing

Problem: --help doesn't display help text

Solutions:

  1. Verify help command is registered (automatic by default)
  2. Add command descriptions:
cli.addCommand({
  name: "build",
  description: "Build the project",  // Required for help
  execute: ({ logger }) => {},
});
  1. Manually register help command:
import { HelpCommand } from "@visulima/cerebro/command/help";
cli.addCommand(HelpCommand);

Exit Code Issues

Problem: CLI exits with code 0 even on errors

Solution: Use error handler plugin:

import { errorHandlerPlugin } from "@visulima/cerebro/plugin/error-handler";

cli.use(errorHandlerPlugin({ exitOnError: true }));

Or manually set exit code:

cli.addCommand({
  name: "test",
  execute: async ({ logger }) => {
    try {
      await runTests();
    } catch (error) {
      logger.error(error.message);
      process.exit(1);  // Exit with error code
    }
  },
});

Performance Issues

Problem: CLI is slow to start

Solutions:

  1. Lazy-load heavy dependencies:
cli.addCommand({
  name: "heavy",
  execute: async () => {
    // Load only when command runs
    const { heavyFunction } = await import("./heavy-module");
    await heavyFunction();
  },
});
  1. Minimize plugin initialization work
  2. Use dynamic imports for optional features

Cross-Runtime Issues

Problem: CLI works in Node.js but not in Deno/Bun

Solutions:

  1. Avoid Node.js-specific APIs
  2. Use Cerebro's runtime abstractions:
import { getEnv, getCwd } from "@visulima/cerebro";

cli.addCommand({
  execute: ({ logger }) => {
    const env = getEnv();      // Works in all runtimes
    const cwd = getCwd();      // Works in all runtimes
    logger.log(`CWD: ${cwd}`);
  },
});
  1. Test in all target runtimes

Debugging

Enable debug output:

CEREBRO_OUTPUT_LEVEL=debug my-cli build

Add debug logging:

cli.addCommand({
  name: "build",
  execute: ({ logger }) => {
    if (process.env.CEREBRO_OUTPUT_LEVEL === "debug") {
      logger.log("Debug: Starting build...");
    }
    // Build logic
  },
});
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues