addFile returns this error on server code: UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
See original GitHub issueHi all, Trying to run addFile on a meteor method (server) gives me this error:
UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
I have run the addFile method using async/await; without async/await; and with Async (meteorhacks:async). I always get same error.
Note: the document is saved on the collection in mongo. But the error occurs and the method does not return normally to the client.
This is my collection:
import { FilesCollection } from 'meteor/ostrio:files';
import SimpleSchema from 'simpl-schema';
const mySchema = {
...FilesCollection.schema,
};
export const FluentReports = new FilesCollection({
collectionName: 'fluentReports',
allowClientCode: false, // Disallow remove files from Client
debug: true
});
FluentReports.collection.attachSchema(new SimpleSchema(mySchema));
This is my meteor method:
Meteor.methods({
'requerimientos.reports.general_4'() {
const user = Meteor.user();
const fileName = `req.report.general.${user._id}.pdf`;
let finalPath = path.join(process.env.PWD, `/.temp`, fileName);
finalPath = finalPath.replace(/\\/g, "/");
let response = null;
response = Async.runSync(function(done) {
Promise.resolve(
FluentReports.addFile(finalPath, {
fileName: fileName,
type: 'pdf',
fileId: new Mongo.ObjectID()._str,
meta: {owner: this.userId, createdAt: new Date()}
})
)
.then(function(result) { done(null, result); })
.catch(function (err) { done(err, null); })
.done();
});
if (response.error) {
console.log(`An error occurred: ${response.error.message}`)
}
return {
error: false,
message: "Ok, el reporte ha sido agregado a meteor-files.",
result: response
}
}})
-
Version of
Meteor-Filesyou’re experiencing this issue: ostrio:files@1.14.0 -
Version of
Meteoryou’re experiencing this issue: METEOR@1.10.1 -
Where this issue appears? OS (Mac/Win/Linux)? Browser name and its version? Windows 10 / Chrome: Version 81.0.4044.113 (Official Build) (64-bit)
-
Is it Client or Server issue? Server - addFile on meteor method
This is what is in the console after the error occurs:
I20200423-16:47:47.561(-4)? [FilesCollection] [addFile(C:/requerimientos/.temp/req.report.general.67Qjx32kS7bmhWcfp.pdf)]
W20200423-16:47:52.497(-4)? (STDERR) (node:12008) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
W20200423-16:47:52.498(-4)? (STDERR) at Function.[Symbol.hasInstance] (<anonymous>)
W20200423-16:47:52.499(-4)? (STDERR) at Object.EJSON.isBinary (packages/ejson/ejson.js:426:54)
W20200423-16:47:52.499(-4)? (STDERR) at Object.EJSON.clone (packages/ejson/ejson.js:571:13)
W20200423-16:47:52.499(-4)? (STDERR) at packages/ejson/ejson.js:600:22
W20200423-16:47:52.500(-4)? (STDERR) at Array.forEach (<anonymous>)
W20200423-16:47:52.500(-4)? (STDERR) at Object.EJSON.clone (packages/ejson/ejson.js:599:13)
W20200423-16:47:52.501(-4)? (STDERR) at packages/ejson/ejson.js:600:22
W20200423-16:47:52.501(-4)? (STDERR) at Array.forEach (<anonymous>)
W20200423-16:47:52.501(-4)? (STDERR) at Object.EJSON.clone (packages/ejson/ejson.js:599:13)
W20200423-16:47:52.502(-4)? (STDERR) at packages/ejson/ejson.js:600:22
W20200423-16:47:52.502(-4)? (STDERR) at Array.forEach (<anonymous>)
W20200423-16:47:52.502(-4)? (STDERR) at Object.EJSON.clone (packages/ejson/ejson.js:599:13)
W20200423-16:47:52.503(-4)? (STDERR) at packages/ejson/ejson.js:600:22
W20200423-16:47:52.503(-4)? (STDERR) at Array.forEach (<anonymous>)
W20200423-16:47:52.504(-4)? (STDERR) at Object.EJSON.clone (packages/ejson/ejson.js:599:13)
W20200423-16:47:52.504(-4)? (STDERR) at packages/ejson/ejson.js:600:22
W20200423-16:47:52.504(-4)? (STDERR) (node:12008) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
I20200423-16:47:52.858(-4)? [FilesCollection] [addFile]: req.report.general.67Qjx32kS7bmhWcfp.pdf -> fluentReports
Many thanks …
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
Hi @dr-dimitru , everything is working fine right now. Many thanks for all your help. The final (condensed) code follows:
1) This is how I coded the meteor method:
2) This is how I call the method from client:
3) This is the needed subscription:
Many thanks again. I’m just beginning to know the library; however I can sense its very well done. And very useful.
@mgrivera I’m glad this was quickly solved
Please, support this project by:
Feel free to close it in case if the issue is solved on your end.