I’m not using a 3rd party promises lib, but am struggling with the amount of must run in a fiber errors.
For instance, this is just function is called in a Meteor method.
const notif = async (userId, notifs) => {
try {
console.log('Notif Function Start');
const template = await Assets.getText('email-new-appointment-client.html');
return 'sent';
} catch (error) {
throw new Meteor.Error(500, 'notif functions', error);
}
};
This code isn’t even doing much, just grabbing the template, however it hits the Assets.getText and throws the classic fiber error. Anyone know what’s going on here?
EDIT:
This code above is now working after removing .bablerc presets, however I’m still getting hit with a fiber error on the SyncedCron.add
Assets.getText doesn’t return a promise. You cannot wait for it.
If you remove the await from this code, it still causes the same fiber error.
const insertNotification = async ({ title, active, body, timer, link, apptId, userId, createdAt }) => {
try {
const notifId = await Notifications.insert({
title,
userId,
active,
body,
timer,
link,
apptId,
createdAt,
});
if (timer !== '') {
console.log(notifId, timer);
SyncedCron.add({
name: notifId,
schedule(parser) {
return parser.recur().on(timer).fullDate();
},
job() {
try {
notif(userId, {
userId,
title,
body,
});
const now = new Date();
sent({
_id: notifId,
sentAt: now,
});
SyncedCron.remove(notifId);
return notifId;
} catch (error) {
console.error(error);
throw new Meteor.Error(500, 'cron error', error);
}
},
});
}
} catch (error) {
throw new Meteor.Error(500, 'insertNotification functions', error);
}
};
This code is also having the same fiber errors. If I remove the async and await on the insert, the fiber error is on the insert, if I leave it as is here, the fiber error is on the SyncedCron.add({ .
Where are you calling insertNotification
? If you’re trying it from a REST callback, or something similar, you will need to Meteor.bindEnvironment
your callback.
Similarly, your notif
function shouldn’t be throwing fiber errors if you really are just calling it straight from a synchronous method.
1 Like
That’s why I’m so confused about this, there are no callbacks involved here. No REST calls, nothing that is going off the server or using outside services.
insertNotification is called from within another async function that is called from a method directly. So I guess, two functions removed from the method.
Weird.
I’d probably try cloning the repo and running a meteor update? Are you already on the latest?
I am confused : are you using meteor collections or the underlying Mongo collection ? You are adding await
to all mongo calls when that is not required in Meteor as the collections run synchronously.
example
const sync_collection = new Mongo.Collection("sync_collection")
sync_collection.find()
vs
const async_collection = new Mongo.Collection("async_collection").rawCollection()
await async_collection.find()
2 Likes