I'm getting the following message
UnhandledPromiseRejectionWarning: MissingParameter: The request must contain the parameter DeleteMessageBatchRequestEntry.1.Id.
I think I'm following the documentation to a T at AWS-SDK/SQS
I'm using this code
var params = {
Entries: _.map(_.uniqWith(data.Messages,d=>d.MessageId),d=>({
Id: d.MessageId,
ReceiptHandle: d.ReceiptHandle
})),
QueueUrl: xx.QueueUrl
};
await sqs.deleteMessageBatch(params).promise();
This is what params looks like at the time of sending; looks just like the docs if you ask me...
{
Entries: [
{
Id: "83ba1e18-someid",
ReceiptHandle: "AQEB79CDI1Q+blablabla"
}
]
QueueUrl: "https://sqs.us-west-2.amazonaws.com/somequeeuurl"
}
My system:
aws-sdk: "^2.354.0",
MacOS - current
node 8.12.0
UnhandledPromiseRejectionWarning: MissingParameter: The request must contain the parameter DeleteMessageBatchRequestEntry.1.Id.
I just spent a long time looking at this error and debugging my code. What I finally figured out is that it seems to be trying to say that there needs to be at least one DeleteMessageBatchRequestEntry element in the request – there can't be 0. When I refactored our code and added a check to make sure that we wouldn't make a request if there were no entries in the list, this problem went away.
Is it possible that you are actually sending the following in certain situations?
{
Entries: []
QueueUrl: "https://sqs.us-west-2.amazonaws.com/somequeeuurl"
}
Related
I'm trying to set up the configuration and mock files for jest to parse/ignore image files in order for the tests to pass. Just about every online resource leads me to the jest docs located: https://jestjs.io/docs/webpack#handling-static-assets
which tell you exactly how to handle the situation. However, not in my case. I've tried both options of creating mock files and using a transformer.
My current jest.config.js:
module.exports = {
projects: [
{
displayName: 'Unit',
testMatch: ["**/?(*.)+(spec|test).[tj]s?(x)"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
testPathIgnorePatterns: ["<rootDir>/.next/", "<rootDir>/node_modules/", "<rootDir>/cypress/"],
moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
moduleDirectories: ["node_modules", "bower_components", "shared"],
moduleNameMapper: {
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js'
},
// transform: {
// "\\.js$": "jest",
// "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/fileTransformer.js"
// //'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
// }
},
{
displayName: 'Pacts',
testMatch: ["**/?(*.)+(pacttest).[tj]s?(x)"],
testPathIgnorePatterns: ["<rootDir>/.next/", "<rootDir>/node_modules/", "<rootDir>/cypress/"],
watchPathIgnorePatterns: ["pact/logs/*", "pact/pacts/*"],
}
],
};
my fileMock.js:
module.exports = 'test-file-stub';
My styleMock.js:
module.exports = {};
My fileTransformer.js:
const path = require('path');
module.exports = {
process(src, filename, config, options) {
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
},
};
//export default module.exports;
my directory:
I've been bouncing back and forth trying different options in the configurations but they pretty much all lead me to the same two errors, one when I try to use the transformer, and another without. With the transformer commented out, I get 2 errors thrown at the fileMock.js file:
TypeError: Invalid URL: test-file-stub
Failed to parse src "test-file-stub" on next/image
Both of these are referring to the suggested string for the mock. I initially thought that maybe the string was a placeholder for code to actually handle something. But after some reading, my understanding is that it's actually just supposed to be a string there. Perhaps it's a specific string dependent on my environment? And next/image is where I'm importing the image component from.
I'm prioritizing the mocking (please correct me if I'm wrong) because my understand is the mock tells jest to ignore the image file and proceed with the rest of the test while the transformer actually attempts to change the file type from js to jpg or png or whatever filetype the image is. However, I'm trying everything I can. When I try to the run the tests with the transformer portion uncommented I receive an error before any tests are even run stating:
TypeError: Jest: a transformm must export something.
(which is why there is a commented out export default statement.)
This is my first time ever attempting anything like this and I think I've reached a point where I cannot think of anything else to try. If anybody has experienced anything like this please lay some knowledge on me. I'm not sure if I have the mockfiles set up incorrectly or if it's something in the configurations.
Thanks.
I was able to work around this by creating an image URL here:
https://www.base64-image.de/
and replacing the "test-file-stub" string with the generated URL string.
module.exports = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV/TSotUHeyg4pChOogFURFHrUIRKoRaoVUHk0s/hCYNSYuLo+BacPBjserg4qyrg6sgCH6AuLk5KbpIif9LCi1iPDjux7t7j7t3gFAvMc0KjAGaXjFTibiYya6IwVeE0I9ujCAgM8uYlaQkPMfXPXx8vYvxLO9zf44uNWcxwCcSzzDDrBCvE09tVgzO+8QRVpRV4nPiUZMuSPzIdcXlN84FhwWeGTHTqTniCLFYaGOljVnR1IgniaOqplO+kHFZ5bzFWStVWfOe/IXhnL68xHWag0hgAYuQIEJBFRsooYIYrTopFlK0H/fwDzh+iVwKuTbAyDGPMjTIjh/8D353a+Unxt2kcBzoeLHtjyEguAs0arb9fWzbjRPA/wxc6S1/uQ5Mf5Jea2nRI6BnG7i4bmnKHnC5A/Q9GbIpO5KfppDPA+9n9E1ZoPcW6Fx1e2vu4/QBSFNXyRvg4BAYLlD2mse7Q+29/Xum2d8PVXFym6OczU4AAAAJcEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQflCBkOKh9/wZ+SAAAAGXRFWHRDb21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAAAAxJREFUCNdj+P//PwAF/gL+3MxZ5wAAAABJRU5ErkJggg==';
I am receiving the following error when I call inside getStaticProps and I cannot figure out why:
Error: Error serializing `.lingo` returned from `getStaticProps` in "/".
Reason: `undefined` cannot be serialized as JSON.
I've placed the full app code on CodeSandbox. It won't be able to access the API but it does show where things are defined.
When I run the following query on GraphQL playground I get the expected response:
query {
allTerms {
id
term
slug
lead
}
}
You can see that this query is contained in lingo.service.js in the modules/lingo/services directory on the sandbox but the homepage has the Error serializing error. Is my function export async function getAll() not correct or am I calling it wrong in getStaticProps?
await getAll() is most likely returning undefined which is not serializable JSON. Defaulting to null would be one way to solve the issue.
export async function getStaticProps(context) {
return {
props: { lingo: (await getAll()) ?? null },
};
}
Right, this is supposed to be more of a comment but apparently I don't have enough reputation points to comment. So, I'll answer it like this.
Just check if your props (under getStaticProps()) are named correctly i.e. how they're named in the .json file you're trying to read. I ran into this issue because of a typo I had and just fixed it.
I posted this last week and have made progress since, where I've discovered the packages that VSCode's JSON support is delivered via extensions:
https://github.com/vscode-langservers/vscode-json-languageserver
https://github.com/Microsoft/vscode-json-languageservice
and all the rest. I'm trying to reuse this in an Electron (NodeJS) app. I'm able to fork a process starting the language server and initialize it:
lspProcess = child_process.fork("node_modules/vscode-json-languageserver/out/jsonServerMain.js", [ "--node-ipc" ]);
function initialize() {
send("initialize", {
rootPath: process.cwd(),
processId: process.pid,
capabilities: {
textDocument: true
}
});
}
lspProcess.on('message', function (json) {
console.log(json);
});
and I see that console.log firing and showing it seems to be up correctly.
My thoughts are that I just want to send a textDocument/didChange event as per the LSP:
send('textDocument/didChange', {
textDocument: TextDocument.create('foo://bar/file.json', 'json', 0, JSON.stringify(data))
});
where data is a JSON object representing a file.
When I send that message and other attempts at it I get
error: {code: -32601, message: "Unhandled method textDocument/didChange"}
id: 2
jsonrpc: "2.0"
Any idea what I'm doing wrong here? My main goal is to allow edits through my Electron app and then send the updated JSON to the language server to get schema validation done.
EDIT: I'm even seeing unhandled method initialized when I implement connection.onInitialized() in the jsonServerMain.js.
EDIT2: Update, I figured out where I was going wrong with some of this. initialized and textDocument/didChange are notifications, not requests.
EDIT2: Update, I figured out where I was going wrong with some of this. According to the LSP, initialized and textDocument/didChange are notifications, not requests. Requests have an id field that notifications don't, so when sending a notification, remove the ID field.
I am developing a REST API using node.js and express framework for the first time. I am struggling to fix a very small issue in Node.js and Express, but however, i am unable to do so. I have checked online for all the possible solutions and tried with what all options i know but i am unable to figure out the syntax for the same.
Background : I have one object named “Restaurant” and another object named “Menu” which has a foreign key reference to “Restaurant”.
Now, i have a requirement (common scenario), where i need to send a response to client in the below json format,
{
"Restaurants": [
{
"restaurantid":"5ad36b55c26b685030335e30",
"restaurantname": "ABC Restaurant",
"menus":[
{"menuname":"item1", "menucost":"10"},
{"menuname":"item2", "menucost":"20"}
},
{
"restaurantid":"9sd72b55c26b685030335e31",
"restaurantname": "XYZ Restaurant",
"menus":[
{"menuname":"item3", "menucost":"10"},
{"menuname":"item4", "menucost":"20"}
}
]
}
Problem - I am unable to figure out how to build the "menus" object in node.js and append it to my "menus" variable. I am able to send a response from a single table without any issues. Issue is only when i need to send the menu list based on restaurantid.
I need to get the menus based on the restaurantid.
Below is the code which i am using for returning data from mongodb.
router.get('/', checkAuth, (req, res, next) => {
Restaurant.find()
.exec()
.then(docs => {
res.status(200).json({
count: docs.length,
restaurants: docs.map(doc => {
return {
_id: doc._id,
restaurantname: doc.restaurantname,
menus: ????? <<**This is where i am stuck. Not able to figure out how to write the syntax**>>
}
})
});
})
.catch(err => {
res.status(500).json({
error: err
});
});
});
Please help me with this problem.
Given that MongoDB is designed to store hierarchical documents with relational links between independent collections being something of an afterthought, this seems more like a schema design problem. A menu belongs to a single restaurant (since even individual franchises of a larger chain may have their own modifications or restrictions), so Menus could well work better as a property of Restaurants. It'd certainly be easier for your use case here since you wouldn't need to build anything. If you do need to look at menus alone you can always db.Restaurants.find({...}, {menus: true}); to project just that field.
I have this piece of code:
sendMessage(message) {
let data = {
message
};
this.socket.send('message', data);
}
I'm using eslint and set the object-shorthand rule.
"object-shorthand": [
2,
"always"
],
And get this error:
---
message: 'Unexpected token }'
severity: error
data:
line: 39
column: 14
ruleId: ''
...
But why? Any other way to find what rule is being violated?
If I do this:
sendMessage(message) {
let data = {
message: message
};
this.socket.send('message', data);
}
I get this:
---
message: Expected property shorthand.
severity: error
data:
line: 38
column: 17
ruleId: object-shorthand
...
It's clear what's wrong. Great.
So, how can I find what's going on? eslint is asking for object shorthands (as I told it to) but it is not accepting them... For some other reason?
Having these errors showing up all the time is distracting.
Any help is highly appreciated.
(I'm using the latest gulp-eslint: 1.0.0)
My guess is that the fact that eslint says ruleId: '' points to a bug in eslint, not in your code. You should
search in eslint's open issues (I have tried, but found nothing)
if this bug is not reported, produce a minimal code displaying the bug (sorry, I don't have the time to setup things to do so myself)
if successful, open a new issue