Lexical error in multipart request
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.6k
- Forks
- 237
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to perform a multipart PUT request to CouchDB, but am receiving the following error.
[Sun, 26 Mar 2017 16:21:04 GMT] [debug] [<0.6514.2>] 'PUT' /couch-recliner-test/fake-id {1,1} from "127.0.0.1"
Headers: [{'Accept',"application/json"},
{'Connection',"close"},
{'Content-Length',"665"},
{'Content-Type',"multipart/form-data; boundary=--------------------NODENEEDLEHTTPCLIENT"},
{'Host',"localhost:5984"},
{'User-Agent',"Needle/1.5.0 (Node.js v7.7.3; linux x64)"}]
[Sun, 26 Mar 2017 16:21:04 GMT] [debug] [<0.6514.2>] OAuth Params: []
[Sun, 26 Mar 2017 16:21:04 GMT] [error] [<0.6514.2>] attempted upload of invalid JSON (set log_level to debug to log it)
[Sun, 26 Mar 2017 16:21:04 GMT] [debug] [<0.6514.2>] Invalid JSON: {{error,
{1,
"lexical error: malformed number, a digit is required after the minus sign.\n"}},
<<"----------------------NODENEEDLEHTTPCLIENT\r\nContent-Disposition: form-data; name=\"document_body\"\r\nContent-Type: application/json\r\n\r\n{\"test\":\"data\",\"hello\":22,\"deep\":{\"more\":\"hii\",\"array\":[22,33,145]},\"array\":[\"some\",\"text\",\"here\"],\"description\":\"A longer bit of text with perhaps a line break in it.\\nRight here.\",\"bool\":true,\"_attachments\":{\"fake-attachment.txt\":{\"follows\":true,\"content_type\":\"text/html\",\"length\":46}}}\r\n----------------------NODENEEDLEHTTPCLIENT\r\nContent-Disposition: form-data; name=\"file_0\"; filename=\"fake-attachment.txt\"\r\nContent-Type: text/html\r\n\r\nThis is an example attachment containing text.\r\n----------------------NODENEEDLEHTTPCLIENT--">>}
[Sun, 26 Mar 2017 16:21:04 GMT] [info] [<0.6514.2>] 127.0.0.1 - - PUT /couch-recliner-test/fake-id 400
[Sun, 26 Mar 2017 16:21:04 GMT] [debug] [<0.6514.2>] httpd 400 error response:
{"error":"bad_request","reason":"invalid_json"}
The request looks approximately like this.
const mydata = {
document_body: {
content_type: 'application/json',
value: '{"test":"data","hello":22,"deep":{"more":"hii","array":[22,33,145]},"array":["some","text","here"],"description":"A longer bit of text with perhaps a line break in it.\\nRight here.","bool":true,"_attachments":{"fake-attachment.txt":{"follows":true,"content_type":"text/html","length":46}}}'
},
file_0: {
content_type: 'text/html',
filename: 'fake-attachment.txt',
buffer: mybuffer
}
};
needle.request('PUT', url, mydata, { multipart: true, json: true }, callback);
The key part of the error seems to be.
"lexical error: malformed number, a digit is required after the minus sign.\n"
But I am unsure what it means.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the needle.request('PUT', url, mydata, { multipart: true, json: true }, callback) entry point and reproduce the multipart request against CouchDB using the example payload. Trace how the document_body value and multipart boundaries are assembled; done means the request no longer produces CouchDB's invalid_json lexical error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100