MartinSahlen / cloud-functions-python

Get some python in google cloud functions
203 stars 29 forks source link

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string #45

Closed santhoshdc1590 closed 6 years ago

santhoshdc1590 commented 6 years ago

I built it local and deployed it locally

py-cloud-fn handle_http http -f function.py --python_version 3.5

py-cloud-fn handle_http http --python_version 3.5 -p -f function.py && cd cloudfn/target && npm install && functions deploy handle_http --trigger-http && cd ../..

When I hit the url with POSTMAN

I get this

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string at assertPath (path.js:39:11) at Object.join (path.js:1218:7) at Object.readLogLines (/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/src/emulator/logs.js:33:39) at Controller.getLogs (/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:462:10) at Object.exports.handler (/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/src/cli/commands/logs/read.js:58:14) at Object.runCommand (/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/lib/command.js:235:44) at Object.parseArgs [as _parseArgs] (/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/yargs.js:1014:30) at Object.runCommand (/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/lib/command.js:195:96) at Object.parseArgs [as _parseArgs] (/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/yargs.js:1014:30) at Object.parse (/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/yargs.js:542:25)

I have no idea

/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/src/emulator/logs.js

function readLogLines (filePath, linesToRead, output) {
  try {
    const parts = path.parse(filePath);
    const files = fs
      .readdirSync(parts.dir)
      .filter((file) => file && file.includes(parts.name));
    files.sort();

    // Here, we naively select the newest log file, even if the user wants to
    // display more lines than are available in the newest log file.
    const rl = readline.createInterface({
      input: fs.createReadStream(path.join(parts.dir, files[files.length - 1])),
      terminal: false
    });
    const lines = [];
    rl
      .on('line', (line) => {
        lines.push(line);
      })
      .on('close', () => {
        lines
          .slice(lines.length - linesToRead)
          .forEach((line) => output(`${line}\n`));
      });
  } catch (err) {
    if (err.code === 'ENOENT') {
      output('');
      return;
    }

    throw err;
  }
}

/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js

 /**
   * Writes lines from the Emulator log file in FIFO order.
   * Lines are taken from the end of the file according to the limit argument.
   * That is, when limit is 10 will return the last (most recent) 10 lines from
   * the log (or fewer if there are fewer than 10 lines in the log), in the order
   * they were written to the log.
   *
   * @param {integer} limit The maximum number of lines to write
   */
  getLogs (limit) {
    if (!limit) {
      limit = 20;
    }

    logs.readLogLines(this.config.logFile, limit, (val) => {
      this.write(val);
    });
  }

/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/src/cli/commands/logs/read.js

/**
 * http://yargs.js.org/docs/#methods-commandmodule-providing-a-command-module
 */
exports.command = 'read';
exports.description = DESCRIPTION;
exports.builder = (yargs) => {
  yargs
    .usage(USAGE)
    .options({
      limit: {
        alias: 'l',
        default: 20,
        description: 'Number of log entries to be fetched.',
        type: 'number',
        requiresArg: true
      }
    });

  EXAMPLES['logs.read'].forEach((e) => yargs.example(e[0], e[1]));
};
exports.handler = (opts) => {
  const controller = new Controller(opts);

  let limit = 20;
  if (opts && opts.limit) {
    limit = parseInt(opts.limit, 10);
  }
  controller.getLogs(limit);
};

/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/lib/command.js

// we apply validation post-hoc, so that custom
    // checks get passed populated positional arguments.
    if (!yargs._hasOutput()) yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error)

    if (commandHandler.handler && !yargs._hasOutput()) {
      yargs._setHasOutput()
      if (commandHandler.middlewares.length > 0) {
        const middlewareArgs = commandHandler.middlewares.reduce(function (initialObj, middleware) {
          return Object.assign(initialObj, middleware(innerArgv))
        }, {})
        Object.assign(innerArgv, middlewareArgs)
      }
      const handlerResult = commandHandler.handler(innerArgv)
      if (handlerResult && typeof handlerResult.then === 'function') {
        handlerResult.then(
          null,
          (error) => yargs.getUsageInstance().fail(null, error)
        )
      }

/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/lib/command.js

// what does yargs look like after the buidler is run?
    let innerArgv = parsed.argv
    let innerYargs = null
    let positionalMap = {}
    if (command) {
      currentContext.commands.push(command)
      currentContext.fullCommands.push(commandHandler.original)
    }
    if (typeof commandHandler.builder === 'function') {
      // a function can be provided, which builds
      // up a yargs chain and possibly returns it.
      innerYargs = commandHandler.builder(yargs.reset(parsed.aliases))
      // if the builder function did not yet parse argv with reset yargs
      // and did not explicitly set a usage() string, then apply the
      // original command string as usage() for consistent behavior with
      // options object below.
      if (yargs.parsed === false) {
        if (shouldUpdateUsage(yargs)) {
          yargs.getUsageInstance().usage(
            usageFromParentCommandsCommandHandler(parentCommands, commandHandler),
            commandHandler.description
          )
        }
        innerArgv = innerYargs ? innerYargs._parseArgs(null, null, true, commandIndex) : yargs._parseArgs(null, null, true, commandIndex)
      } else {
        innerArgv = yargs.parsed.argv
      }

/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/yargs.js

const handlerKeys = command.getCommands()
      const skipDefaultCommand = argv[helpOpt] && (handlerKeys.length > 1 || handlerKeys[0] !== '$0')

      if (argv._.length) {
        if (handlerKeys.length) {
          let firstUnknownCommand
          for (let i = (commandIndex || 0), cmd; argv._[i] !== undefined; i++) {
            cmd = String(argv._[i])
            if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) {
              setPlaceholderKeys(argv)
              // commands are executed using a recursive algorithm that executes
              // the deepest command first; we keep track of the position in the
              // argv._ array that is currently being executed.
              return command.runCommand(cmd, self, parsed, i + 1)
            } else if (!firstUnknownCommand && cmd !== completionCommand) {
              firstUnknownCommand = cmd
              break
            }
          }

/Users/santhoshdc/.nvm/versions/node/v9.8.0/lib/node_modules/@google-cloud/functions-emulator/node_modules/yargs/yargs.js:542:25

    freeze()
    if (parseFn) exitProcess = false
    console.log(typeof args)
    const parsed = self._parseArgs(args, shortCircuit)
    if (parseFn) parseFn(exitError, parsed, output)
    unfreeze()

where did I got wrong????