question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addFile returns this error on server code: UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded

See original GitHub issue

Hi 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-Files you’re experiencing this issue: ostrio:files@1.14.0

  • Version of Meteor you’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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mgriveracommented, Apr 24, 2020

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:

'requerimientos.reports.general'() {
       ... ... 
        var addFileSync = Meteor.wrapAsync(FluentReports.addFile, FluentReports);

        let result; 

        try { 
            result = addFileSync(finalPath, { fileName: fileName,
                                              type: 'pdf',
                                              fileId: new Mongo.ObjectID()._str,
                                              meta: {owner: this.userId, createdAt: new Date()}
                                            }); 
        } catch(error) { 
            return { 
                    error: true, 
                    message: `Error: some error has ocurrend: ${error.message}`, 
                }
        }
        return { 
                    error: false, 
                    result: result
                } 
    }

2) This is how I call the method from client:

const getReportGeneral2 = () => {
    Meteor.call('requerimientos.reports.general', (error, result) => {

        if (error || result.error) {
            // report your error 
            return;
        }

        Meteor.subscribe('meteor.files.by.id', result.result._id, () => {

            const report = FluentReports.findOne(result.result._id);    

            if (!report) { 
                // report your error ... 
            } else { 
                const link = ` <a href="${report.link()}?download=true" download="${report.name}" target="_blank">${report.name}$</a> `;
               // show link so user can download the file 
            }
        });
    });
}

3) This is the needed subscription:

import { Meteor } from 'meteor/meteor';
import { FluentReports } from '/imports/api/collections/meteor_files/fluentReports'; 

Meteor.publish("meteor.files.by.id", function (fileId) {
    return FluentReports.collection.find({ _id: fileId });
})

Many thanks again. I’m just beginning to know the library; however I can sense its very well done. And very useful.

0reactions
dr-dimitrucommented, Apr 25, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

addFile returns this error on server code ... - GitHub
addFile returns this error on server code: UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded #740.
Read more >
JavaScript RangeError: Maximum Call Stack Size Exceeded
The RangeError: Maximum call stack size exceeded is thrown when a function call is made that exceeds the call stack size. This can...
Read more >
javascript - Maximum call stack size exceeded error
It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you...
Read more >
JavaScript Error: Maximum Call Stack Size Exceeded
This error is a RangeError. A RangeError typically means an error has occurred outside of a code's argument value for its parameter. Now...
Read more >
RangeError: Maximum call stack size exceeded - Educative.io
In this shot, we will see how to fix the “RangeError: Maximum call stack size exceeded” error. ... The most common source for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found