Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Unexpected end of input #26

Closed
babolivier opened this issue Jul 18, 2015 · 7 comments
Closed

Unexpected end of input #26

babolivier opened this issue Jul 18, 2015 · 7 comments
Labels

Comments

@babolivier
Copy link

When trying to create an object in the DataSystem with cozydb@0.0.19 for a side project, I get this error in the DataSystem logs:

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at parse (/usr/local/cozy/apps/data-system/node_modules/americano/node_modules/body-parser/index.js:65:17)
    at /usr/local/cozy/apps/data-system/node_modules/americano/node_modules/body-parser/index.js:180:18
    at IncomingMessage.onEnd (/usr/local/cozy/apps/data-system/node_modules/americano/node_modules/body-parser/node_modules/raw-body/index.js:117:7)
    at IncomingMessage.g (events.js:180:16)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

I just switched to version 0.0.16 for now and it's working fine so far.

@frankrousseau
Copy link
Contributor

Sad. Thank you for reporting.

@aenario
Copy link
Contributor

aenario commented Jul 20, 2015

@babolivier, could you show the code which product this output ?

@babolivier
Copy link
Author

Here it is: https://github.com/babolivier/cozy-library/blob/development/server/models/book.coffee#L45
I think it changed a bit since this error, but the way the create method is called is the same (I'll have to make a few tests later today).

@aenario
Copy link
Contributor

aenario commented Jul 21, 2015

I made a few test and am totally unable to reproduce this bug.

Could you please :
1 - give me sample of what the book object is like
2 - add a console.log(opts); at yourproject/node_modules/cozydb/node_modules/request-json-light/main.js#100

Thanks !

@babolivier
Copy link
Author

Hi @aenario,

Sorry for the delay in my reply.

The book object is defined just above the line I sent you, so I believe you're asking be for an example of the item object, here is one:

{ Author: [ 'Carroll Quigley', 'Pierre Hillard' ],
  Binding: [ 'Broché' ],
  EAN: [ '9782355120626' ],
  EANList: [ { EANListElement: [Object] } ],
  ISBN: [ '2355120625' ],
  ItemDimensions: [ { Height: [Object], Length: [Object], Width: [Object] } ],
  Label: [ 'Le retour aux sources' ],
  Languages: [ { Language: [Object] } ],
  ListPrice: 
   [ { Amount: [Object],
       CurrencyCode: [Object],
       FormattedPrice: [Object] } ],
  Manufacturer: [ 'Le retour aux sources' ],
  NumberOfPages: [ '454' ],
  PackageDimensions: 
   [ { Height: [Object],
       Length: [Object],
       Weight: [Object],
       Width: [Object] } ],
  ProductGroup: [ 'Book' ],
  ProductTypeName: [ 'ABIS_BOOK' ],
  PublicationDate: [ '2015-05-30' ],
  Publisher: [ 'Le retour aux sources' ],
  Studio: [ 'Le retour aux sources' ],
  Title: [ 'Histoire secrète de l\'oligarchie anglo-américaine' ] }

Then I added the console.log(opts); in the file you mentionned, here's the output:

{ headers: 
   { accept: 'application/json',
     'user-agent': 'request-json/1.0',
     'content-type': 'application/json',
     authorization: 'Basic MC41YW13eHByeXd1OGN3aGZyOnRva2Vu',
     'Content-Length': 395 },
  host: 'localhost',
  port: '9101',
  protocol: 'http:',
  path: '/data/',
  requestFactory: 
   { parsers: 
      { name: 'parsers',
        constructor: [Function],
        max: 1000,
        list: [Object] },
     STATUS_CODES: 
      { '100': 'Continue',
        '101': 'Switching Protocols',
        '102': 'Processing',
        '200': 'OK',
        '201': 'Created',
        '202': 'Accepted',
        '203': 'Non-Authoritative Information',
        '204': 'No Content',
        '205': 'Reset Content',
        '206': 'Partial Content',
        '207': 'Multi-Status',
        '300': 'Multiple Choices',
        '301': 'Moved Permanently',
        '302': 'Moved Temporarily',
        '303': 'See Other',
        '304': 'Not Modified',
        '305': 'Use Proxy',
        '307': 'Temporary Redirect',
        '400': 'Bad Request',
        '401': 'Unauthorized',
        '402': 'Payment Required',
        '403': 'Forbidden',
        '404': 'Not Found',
        '405': 'Method Not Allowed',
        '406': 'Not Acceptable',
        '407': 'Proxy Authentication Required',
        '408': 'Request Time-out',
        '409': 'Conflict',
        '410': 'Gone',
        '411': 'Length Required',
        '412': 'Precondition Failed',
        '413': 'Request Entity Too Large',
        '414': 'Request-URI Too Large',
        '415': 'Unsupported Media Type',
        '416': 'Requested Range Not Satisfiable',
        '417': 'Expectation Failed',
        '418': 'I\'m a teapot',
        '422': 'Unprocessable Entity',
        '423': 'Locked',
        '424': 'Failed Dependency',
        '425': 'Unordered Collection',
        '426': 'Upgrade Required',
        '428': 'Precondition Required',
        '429': 'Too Many Requests',
        '431': 'Request Header Fields Too Large',
        '500': 'Internal Server Error',
        '501': 'Not Implemented',
        '502': 'Bad Gateway',
        '503': 'Service Unavailable',
        '504': 'Gateway Time-out',
        '505': 'HTTP Version Not Supported',
        '506': 'Variant Also Negotiates',
        '507': 'Insufficient Storage',
        '509': 'Bandwidth Limit Exceeded',
        '510': 'Not Extended',
        '511': 'Network Authentication Required' },
     IncomingMessage: { [Function: IncomingMessage] super_: [Object] },
     OutgoingMessage: { [Function: OutgoingMessage] super_: [Object] },
     ServerResponse: { [Function: ServerResponse] super_: [Object] },
     Agent: { [Function: Agent] super_: [Object], defaultMaxSockets: 5 },
     globalAgent: 
      { domain: null,
        _events: [Object],
        _maxListeners: 10,
        options: {},
        requests: {},
        sockets: [Object],
        maxSockets: 5,
        createConnection: [Function] },
     ClientRequest: { [Function: ClientRequest] super_: [Object] },
     request: [Function],
     get: [Function],
     Server: { [Function: Server] super_: [Object] },
     createServer: [Function],
     _connectionListener: [Function: connectionListener],
     Client: [Function: deprecated],
     createClient: [Function: deprecated] },
  method: 'POST' }

By the way, I obviously checked, and I get the same bug with the current version of the file: https://github.com/babolivier/cozy-library/blob/development/server/models/book.coffee

Hope this'll help.

@aenario
Copy link
Contributor

aenario commented Jul 22, 2015

Ok, Got it !

It is caused by the accents :

> JSON.stringify(a)
'{"test":"accent éguè"}'
> JSON.stringify(a).length
22
> new Buffer(JSON.stringify(a)).length
24

So, we set the Content-Length at 22 but, the byte length is 24, so the DS missed the last two char and bug ensues. I couldn't reproduce because I was testing with ASCII characters only !

@clochix
Copy link
Contributor

clochix commented Jul 28, 2015

Hi @babolivier,
The fix should be available in latest version of CozyDB. could you give it a try please ? Thanks !

@aenario aenario closed this as completed Nov 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants