{"record":{"id":"1fa8e0c993a9682f","repo":"nodejs/node","slug":"search-must-be-called-with-arguments","errorCode":null,"errorMessage":"search must be called with arguments","messagePattern":"search must be called with arguments","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/commands/search.js","lineNumber":35,"sourceCode":"    'searchexclude',\n    'registry',\n    'prefer-online',\n    'prefer-offline',\n    'offline',\n  ]\n\n  static usage = ['<search term> [<search term> ...]']\n\n  async exec (args) {\n    const opts = {\n      ...this.npm.flatOptions,\n      ...this.npm.flatOptions.search,\n      include: args.map(s => s.toLowerCase()).filter(Boolean),\n      exclude: this.npm.flatOptions.search.exclude.split(/\\s+/),\n    }\n\n    if (opts.include.length === 0) {\n      throw new Error('search must be called with arguments')\n    }\n\n    // Used later to figure out whether we had any packages go out\n    let anyOutput = false\n\n    // Grab a configured output stream that will spit out packages in the desired format.\n    const outputStream = formatSearchStream({\n      args, // --searchinclude options are not highlighted\n      ...opts,\n      npm: this.npm,\n    })\n\n    log.silly('search', 'searching packages')\n    const p = new Pipeline(\n      libSearch.stream(opts.include, opts),\n      outputStream\n    )\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/search.js#L17-L53","documentation":"Thrown by `npm search` when, after lowercasing and filtering falsy values, the include list (`args`) is empty. The command requires at least one non-empty search term; `npm search` with no arguments (or only whitespace/empty strings) is meaningless and rejected before any registry call.","triggerScenarios":"Calling `npm search` with zero positional args, or with args that all filter to falsy after `s.toLowerCase()` and `Boolean` (e.g. empty strings).","commonSituations":"Scripted invocation that passes an empty variable (`npm search \"$QUERY\"` with `QUERY` unset); typo'd flag that consumed the term; shell quoting that stripped the argument.","solutions":["Provide one or more non-empty search terms: `npm search lodash`.","In scripts, guard the variable before calling: `npm search \"$QUERY\"` only when `QUERY` is set.","Validate the args array length in your wrapper before invoking the CLI."],"exampleFix":"// before\nnpm search   // no term\n// after\nnpm search express","handlingStrategy":"validation","validationCode":"function assertSearchArgs(args) {\n  const include = (args || []).map(s => String(s).toLowerCase()).filter(Boolean)\n  if (include.length === 0) {\n    throw new Error('npm search requires at least one non-empty search term')\n  }\n  return include\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In shell scripts, guard: `[ -n \"$QUERY\" ] && npm search \"$QUERY\"`.","Validate that search arrays are non-empty before invoking the CLI programmatically.","Watch for unset environment variables expanding to empty args."],"tags":["search","argument-validation","npm-cli"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}