question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: Cannot read property 'length' of undefined

See original GitHub issue

[Enter steps to reproduce below:]

Atom Version: 1.7.3 System: Mac OS X 10.11.4 Thrown From: Remote-FTP package, v0.8.1

Stack Trace

Uncaught TypeError: Cannot read property ‘length’ of undefined

At buffer.js:554

TypeError: Cannot read property 'length' of undefined
    at Buffer.write (buffer.js:554:13)
    at SFTPStream.stat (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:1599:7)
    at SFTPWrapper.stat (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/lib/SFTPWrapper.js:87:23)
    at /Users/Ingmar/.atom/packages/Remote-FTP/lib/connectors/sftp.js:154:18
    at state.requests.(anonymous function).cb (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:1885:16)
    at SFTPStream._transform (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:387:17)
    at SFTPStream.Transform._read (_stream_transform.js:167:10)
    at SFTPStream._read (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:170:15)
    at SFTPStream.Transform._write (_stream_transform.js:155:12)
    at doWrite (_stream_writable.js:292:12)
    at writeOrBuffer (_stream_writable.js:278:5)
    at SFTPStream.Writable.write (_stream_writable.js:207:11)
    at Channel.ondata (_stream_readable.js:528:20)
    at emitOne (events.js:77:13)
    at Channel.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Channel.Readable.push (_stream_readable.js:110:10)
    at SSH2Stream.<anonymous> (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/lib/Channel.js:146:15)
    at emitOne (events.js:77:13)
    at SSH2Stream.emit (events.js:169:7)
    at parsePacket (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:3163:10)
    at SSH2Stream._transform (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:551:13)
    at SSH2Stream.Transform._read (_stream_transform.js:167:10)
    at SSH2Stream._read (/Users/Ingmar/.atom/packages/Remote-FTP/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:212:15)
    at SSH2Stream.Transform._write (_stream_transform.js:155:12)
    at doWrite (_stream_writable.js:292:12)
    at writeOrBuffer (_stream_writable.js:278:5)
    at SSH2Stream.Writable.write (_stream_writable.js:207:11)
    at Socket.ondata (_stream_readable.js:528:20)
    at emitOne (events.js:77:13)

Commands

     -1:29.1.0 core:paste (atom-text-editor.editor.is-focused)
     -1:28.7.0 core:move-up (atom-text-editor.editor.is-focused)
     -1:28.4.0 core:move-right (atom-text-editor.editor.is-focused)
  2x -1:28.2.0 core:move-up (atom-text-editor.editor.is-focused)
  2x -1:27 core:select-down (atom-text-editor.editor.is-focused)
     -1:26.6.0 core:backspace (atom-text-editor.editor.is-focused)
     -1:26.4.0 core:save (atom-text-editor.editor.is-focused)
     -1:16.8.0 core:move-down (atom-text-editor.editor.is-focused)
     -1:16.2.0 editor:toggle-line-comments (atom-text-editor.editor.is-focused)
     -1:15.9.0 core:move-down (atom-text-editor.editor.is-focused)
  2x -1:15.5.0 core:select-down (atom-text-editor.editor.is-focused)
     -1:14.8.0 editor:toggle-line-comments (atom-text-editor.editor.is-focused)
     -1:14.5.0 core:save (atom-text-editor.editor.is-focused)
     -1:03.2.0 remote-ftp:disconnect (atom-text-editor.editor.is-focused)
     -0:18.5.0 remote-ftp:sync-with-remote (div.header.list-item)
     -0:13.1.0 remote-ftp:connect (ol.ftptree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)

Config

{
  "core": {}
}

Installed Packages

# User
Remote-FTP, v0.8.1

# Dev
No dev packages

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

5reactions
LeonBladecommented, Nov 6, 2017

The error is located here: https://github.com/icetee/remote-ftp/blob/master/lib/client.js#L525

In my case, self.info.remote was blank (as the stack trace implies) which is why this line fails. However, this method takes in remote as well which is the absolute path to the file you’re trying to download, for example: /var/www/test.php.

The fix for users now is to include the remote in the config and set it to / or something else. For the case of fixing the code, there is a check normally that’s supposed to fix this issue, but it doesn’t seem to happen.

It’s odd because the code that I have in the plugin isn’t shown here on the repo, at least not in the master branch. The code tries to default remote to / in order to fix this problem, but it doesn’t seem to work at all.

Regardless, this code doesn’t set self.info.remote if it isn’t found either. The code in question I will post here since I don’t know what branch it’s supposed to be in:

if (self.info.remote) {
    self.root.path = `/${self.info.remote.replace(/^\/+/, '')}`;
} else {
    self.root.path = '/';
}

A simple solution would be to also set the self.info.remote here to prevent situation like this issue to come up.

For those that come upon this error before a fix is provided, just add remote into your config and it should work fine.

0reactions
Pato05commented, Dec 30, 2018

[Enter steps to reproduce:]

  1. Connect to a ftp server
  2. Double click a file

Atom: 1.33.1 x64 Electron: 2.0.16 OS: Windows 8.1 Thrown From: remote-ftp package 2.2.2

Stack Trace

Uncaught TypeError: Cannot read property ‘length’ of undefined

At C:\Users\Loris\.atom\packages\remote-ftp\lib\client.js:628

TypeError: Cannot read property 'length' of undefined
    at Client.toLocal (/packages/remote-ftp/lib/client.js:628:43)
    at ConnectorFTP._getFile (/packages/remote-ftp/lib/connectors/ftp.js:192:31)
    at /packages/remote-ftp/lib/connectors/ftp.js:530:14
    at /packages/remote-ftp/lib/connectors/ftp.js:185:9
    at Object.cb (/packages/remote-ftp/node_modules/@icetee/ftp/lib/connection.js:368:5)
    at /packages/remote-ftp/node_modules/@icetee/ftp/lib/connection.js:122:20)
    at emitTwo (events.js:131:20)
    at Parser.emit (events.js:214:7)
    at Parser.write (/packages/remote-ftp/node_modules/@icetee/ftp/lib/parser.js:78:12)
    at Socket.ondata (/packages/remote-ftp/node_modules/@icetee/ftp/lib/connection.js:293:20)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:594:20)

Commands

     -0:46.1.0 grammar-selector:show (atom-text-editor.editor.is-focused)
     -0:31.6.0 core:confirm (input.hidden-input)

Non-Core Packages

remote-ftp 2.2.2 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property Length of Undefined in JavaScript
The JavaScript TypeError: Cannot read property 'length' of undefined occurs when the length property is read on an undefined variable.
Read more >
Cannot read properties of undefined (reading 'length') - TrackJS
This message indicates that our code expects to have an object with a length property, but that object was not present. length is...
Read more >
TypeError: Cannot read property 'length' of Undefined in JS
The "Cannot read property 'length' of undefined" error occurs when accessing the length property on an undefined value. To solve the error, make...
Read more >
Typeerror: Cannot Read Property 'length' of Undefined
A typeerror length of undefined can indicate that the actual type of an operand is different from the expected type. This error can...
Read more >
[SOLVED] Cannot Read Property 'length' of Undefined in JS
To fix the “cannot read property 'length' of undefined” error, perform an undefined check on the variable before accessing the length property ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found