nodejs/node · error · Exception

Not enough arguments

Error message

Not enough arguments

What it means

mac_tool.py's MacTool.Dispatch expects argv-style args whose first element names the subcommand (e.g. 'copy-bundle-resource'). It maps that name to an Exec<Name> method. With an empty args list there is no subcommand to dispatch, so it raises a plain Exception.

Source

Thrown at tools/gyp/pylib/gyp/mac_tool.py:38

import subprocess
import sys
import tempfile


def main(args):
    executor = MacTool()
    if (exit_code := executor.Dispatch(args)) is not None:
        sys.exit(exit_code)


class MacTool:
    """This class performs all the Mac tooling steps. The methods can either be
    executed directly, or dispatched from an argument list."""

    def Dispatch(self, args):
        """Dispatches a string command to a method."""
        if len(args) < 1:
            raise Exception("Not enough arguments")

        method = "Exec%s" % self._CommandifyName(args[0])
        return getattr(self, method)(*args[1:])

    def _CommandifyName(self, name_string):
        """Transforms a tool name like copy-info-plist to CopyInfoPlist"""
        return name_string.title().replace("-", "")

    def ExecCopyBundleResource(self, source, dest, convert_to_binary):
        """Copies a resource file to the bundle/Resources directory, performing any
        necessary compilation on each resource."""
        convert_to_binary = convert_to_binary == "True"
        extension = os.path.splitext(source)[1].lower()
        if os.path.isdir(source):
            # Copy tree.
            # TODO(thakis): This copies file attributes like mtime, while the
            # single-file branch below doesn't. This should probably be changed to
            # be consistent with the single-file branch.

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Inspect the generated Makefile rule and confirm the mac-tool invocation includes the subcommand token.
  2. If invoking MacTool directly, pass the subcommand name as args[0].
  3. Regenerate the project with gyp so the Makefile rule is rewritten correctly.

Example fix

// before
$ python mac_tool.py
# or MacTool().Dispatch([])
// after
$ python mac_tool.py copy-bundle-resource src.png out.png True
# or MacTool().Dispatch(['copy-bundle-resource', 'src.png', 'out.png', 'True'])
Defensive patterns

Strategy: validation

Validate before calling

# If invoking MacTool directly, guard the dispatch.
if not args:
    raise SystemExit('usage: mac_tool.py <subcommand> [args...]')
executor.Dispatch(args)

Type guard

def has_subcommand(args) -> bool:
    return isinstance(args, (list, tuple)) and len(args) >= 1 and bool(args[0])

Try / catch

try:
    executor.Dispatch(args)
except Exception as e:
    if 'Not enough arguments' in str(e):
        sys.stderr.write('usage: mac_tool.py <subcommand> [args...]\n')
        sys.exit(2)
    raise

Prevention

When it happens

Trigger: MacTool.Dispatch is called with an empty list/tuple (len(args) < 1). This is normally driven by the gyp-mac-tool wrapper invoked from the Makefile generator.

Common situations: A broken Makefile/gyp rule that invokes 'gyp-mac-tool' with no arguments; calling MacTool().Dispatch([]) directly in a test; argument quoting bug that swallowed the subcommand.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/21d9500d334ff7e1. Report an issue: GitHub.