Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: this._parser.write is not a function #4

Closed
potravniy opened this issue Dec 13, 2019 · 3 comments
Closed

TypeError: this._parser.write is not a function #4

potravniy opened this issue Dec 13, 2019 · 3 comments
Assignees

Comments

@potravniy
Copy link

I like formidable-serverless, it really solved my pain with Firebase functions.
It is used as following:

const formidable = require("formidable-serverless");

function getBodyFields(req) {
  var form = new formidable.IncomingForm();
  return new Promise((resolve, reject) => {
    form.parse(req, (err, fields) => {
      if (err) reject(err);
      else if (Object.keys(fields).length === 0) reject(new Error("No data to upload."));
      else resolve(fields);
    });
  });
}

api.post(apiPath, async (req, res) => {
  try {
    const { base64, width, height, ext } = await getBodyFields(req);
  } catch (error) {
    console.error(error);
    res.status(500).send(error);
  }
});

Having sent an empty request without any field and file the unhandled error happened:

TypeError: this._parser.write is not a function
at IncomingForm.write (/functions/node_modules/formidable/lib/incoming_form.js:159:34)
at IncomingForm.formidable.IncomingForm.parse (/functions/node_modules/formidable-serverless/lib/index.js:58:10)
at Promise (/functions/api.js:114:10)
at new Promise ()
at getBodyFields (/functions/api.js:113:10)
at api.post (/functions/api.js:31:50)
at Layer.handle [as handle_request] (/functions/node_modules/express/lib/router/layer.js:95:5)
at next (/functions/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/functions/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/functions/node_modules/express/lib/router/layer.js:95:5)

"Unhandled" means that error was not cought with neither
if (err) reject(err);
nor
if (Object.keys(fields).length === 0) reject(new Error("No data to upload."));

It would be good to catch this error in callback function as err.

Thank you!

@Amit-A
Copy link
Owner

Amit-A commented Dec 22, 2019

Yes, it would be good to catch the error in the callback function.

Looks like the parent formidable repo fixed this issue recently: node-formidable/formidable@c8bba1b#diff-38e857ca3aca5cc608230f4e8d0b3ea5

I will push an update soon.

@Amit-A Amit-A self-assigned this Dec 22, 2019
@Amit-A
Copy link
Owner

Amit-A commented Dec 22, 2019

This should fix it.

@Amit-A
Copy link
Owner

Amit-A commented Dec 22, 2019

Published updated version (v1.0.3) to npm.

@Amit-A Amit-A closed this as completed Dec 22, 2019
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

No branches or pull requests

2 participants