UnhandledPromiseRejectionWarning: Error: Meteor.userId can only be invoked in method calls or publications.
Describe the bug It fails when invoking a Meteor api function:
20231229-11:31:10.737(-3)? (STDERR) (node:15963) UnhandledPromiseRejectionWarning: Error: Meteor.userId can only be invoked in method calls or publications.
W20231229-11:31:10.738(-3)? (STDERR) at AccountsServer.userId (packages/accounts-base/accounts_server.js:125:13)
W20231229-11:31:10.738(-3)? (STDERR) at Object.Meteor.userId (packages/accounts-base/accounts_common.js:421:32)
W20231229-11:31:10.739(-3)? (STDERR) at server/XLSXExport.js:53:15
W20231229-11:31:10.739(-3)? (STDERR) at doCall (packages/communitypackages:picker/lib/implementation.js:118:14)
W20231229-11:31:10.739(-3)? (STDERR) at PickerImp._processRoute (packages/communitypackages:picker/lib/implementation.js:112:5)
W20231229-11:31:10.739(-3)? (STDERR) at packages/communitypackages:picker/lib/implementation.js:79:16
W20231229-11:31:10.739(-3)? (STDERR) at processNextMiddleware (packages/communitypackages:picker/lib/implementation.js:65:7)
W20231229-11:31:10.739(-3)? (STDERR) at processNextRoute (packages/communitypackages:picker/lib/implementation.js:75:9)
W20231229-11:31:10.739(-3)? (STDERR) at PickerImp._dispatch (packages/communitypackages:picker/lib/implementation.js:97:3)
W20231229-11:31:10.739(-3)? (STDERR) at packages/communitypackages:picker/lib/instance.js:6:10
W20231229-11:31:10.740(-3)? (STDERR) at /Users/edoelk/.meteor/packages/promise/.0.12.2.tshzeo.64bu++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40
W20231229-11:31:10.740(-3)? (STDERR) (Use `node --trace-warnings ...` to show where the warning was created)
W20231229-11:31:10.740(-3)? (STDERR) (node:15963) 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: 1)
W20231229-11:31:10.740(-3)? (STDERR) (node:15963) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
To Reproduce This is the offending code (/server/export.js):
Picker.route('/download/:exportId', function (params, req, res, next) {
if (!Meteor.userId()) {
res.writeHead(401)
res.end()
return
}
const exportEntry = ExportsCollection.findOne({ _id: params.exportId, owner: Meteor.userId() })
if (!exportEntry) {
res.writeHead(404)
res.end()
return
}
const filePath = `${process.env.IC_EXPORT_LOCATION || '/tmp'}/${exportEntry.physicalFileName}`
res.setHeader('Content-disposition', 'attachment; filename=' + exportEntry.downloadFileName)
res.setHeader('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
const filestream = fs.createReadStream(filePath)
filestream.pipe(res)
})
Expected behavior The documentation states: "You can use Meteor APIs inside this callback (runs inside a Fiber)"
Screenshots N/A
Desktop (please complete the following information):
- OS: macOS 14.2
- Browser: N/A (server failure)
- Meteor Version: 2.14
- Version 1.1.1
Smartphone (please complete the following information): N/A
Additional context N/A
Thank you for submitting this issue!
We, the Members of Meteor Community Packages take every issue seriously. Our goal is to provide long-term lifecycles for packages and keep up with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem.
However, we contribute to these packages mostly in our free time. Therefore, we can't guarantee your issues to be solved within certain time.
If you think this issue is trivial to solve, don't hesitate to submit a pull request, too! We will accompany you in the process with reviews and hints on how to get development set up.
Please also consider sponsoring the maintainers of the package. If you don't know who is currently maintaining this package, just leave a comment and we'll let you know
I think this issue could very well be solved once this package is updated for Meteor 3 due to fibers removal. I'm gonna close this for now.