gwomacks / php-debug

Atom Text Editor package for PHP debugging
MIT License
119 stars 31 forks source link

Uncaught TypeError: Cannot read property 'length' of null #277

Open SimoModaJob opened 6 years ago

SimoModaJob commented 6 years ago

[Enter steps to reproduce:]

  1. ...
  2. ...

Atom: 1.26.1 x64 Electron: 1.7.11 OS: Ubuntu 17.10 Thrown From: php-debug package 0.3.0

Stack Trace

Uncaught TypeError: Cannot read property 'length' of null

At /home/simo/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:135

TypeError: Cannot read property 'length' of null
    at DbgpInstance.parse (/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:135:29)
    at DbgpInstance.handleData (/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:258:10)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at TCP.onread (net.js:560:20)

Commands

Non-Core Packages

atom-debug-ui 1.0.1 
atom-ide-ui 0.11.1 
ide-php 0.7.14 
php-debug 0.3.0 
cchamplin commented 6 years ago

Can you enable protocol debugging in the settings for PHP-Debug, and then paste me the contents of the console for the Atom Developer Console after this error occurs?

y-morozov commented 6 years ago

I have the same error. Here's my output

-1525441763246.log

cchamplin commented 6 years ago

Thank @y-morozov anyway you can provide me the same file with "Xdebug DBGP Protocol Debugging" checked?

y-morozov commented 6 years ago

@cchamplin It was checked. Am I missing something?

cchamplin commented 6 years ago

You may need to change the log level in the atom developer tools to "Verbose"

y-morozov commented 6 years ago

Ok, here you are. -1525442937001.log

y-morozov commented 6 years ago

Expanded arrays: -1525443111211.log

cchamplin commented 6 years ago

Okay I'm still having trouble reproducing this, or seeing the error.

If you're willing can you find the php-debug plugin on your machine and perform the following:

  1. Open php-debug/lib/engines/dbgp/dbgp-instance.js
  2. Replace the handleData function starting on line ~253
  handleData (data) {
    if (this._buffers == undefined || this._buffers == null) {
      return;
    }
    if (data == null) {
      console.log("null data");
    } else {
      console.log(data.toString("hex"))
      console.log("buffer status - bufferIdx: " + this._bufferIdx + " bufferReadIdx: " + this._bufferReadIdx);
    }
    this._buffers[this._bufferIdx++ % this._bufferSize] = data
    this.parse()
  }
  1. Send me the log after restarting atom
y-morozov commented 6 years ago

@cchamplin okay, here it is -1525447807355.log

My steps to reproduce:

  1. Set breakpoint
  2. Start debugging session
  3. Click "Step over" (or any other button)

My setup:

Website code runs inside VirtualBox (PHP 7.1.15-0ubuntu0.17.10.1), with remote connect to Atom debugger (MacOs, PHP 7.1.14)

cchamplin commented 6 years ago

Thanks a bunch!

Can you change 159 and 160 in that file from:

buffer = null;
writeIdx = buffer.length-idx;

to

writeIdx = buffer.length-idx;
buffer = null;

and let me know if the problem persists or you still have errors in your log

y-morozov commented 6 years ago

Seems like all errors disappeared!

y-morozov commented 6 years ago

Actually one error still appears:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at /Users/user/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:210:29
    at Parser.<anonymous> (/Users/user/.atom/packages/php-debug/node_modules/xml2js/lib/parser.js:303:18)
    at emitOne (events.js:96:13)
    at Parser.emit (events.js:191:7)
    at Parser.exports.Parser.Parser.parseString (/Users/user/.atom/packages/php-debug/node_modules/xml2js/lib/parser.js:313:16)
    at Parser.parseString (/Users/user/.atom/packages/php-debug/node_modules/xml2js/lib/parser.js:5:59)
    at exports.parseString (/Users/user/.atom/packages/php-debug/node_modules/xml2js/lib/parser.js:354:19)
    at DbgpInstance.parseXml (/Users/user/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:206:13)
    at DbgpInstance.parse (/Users/user/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:183:12)
    at DbgpInstance.parse (/Users/user/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:189:14)
    at DbgpInstance.handleData (/Users/user/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:264:10)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at TCP.onread (net.js:560:20)
chrisolof commented 6 years ago

I'm also hitting this bug after upgrading to 0.3.0 today. I get two Uncaught TypeError: Cannot read property 'length' of null errors on breakpoint hit:

And no useful info shows in the PHP Debug window.

Atom 1.21.0-beta1 atom-debug-ui 1.0.1 atom-ide-ui 0.11.1 ide-php 0.7.14 php-debug 0.3.0

cchamplin commented 6 years ago

This should be fixed in v0.3.1 which just went out. Please let me know if you continue to experience issues around this.

costafrancesco94 commented 6 years ago

This morning, along with some other strange comportament, the error come out again... :(

`` [Enter steps to reproduce:]

  1. Set breakpoint to index.php
  2. Move in the code with step over and step in: ok
  3. Move with play and set breakpoint in another file, when you arrive (and it go in the right file in the right line) you are blocked and only exit point is detatch

Atom: 1.26.1 x64 Electron: 1.7.11 OS: Ubuntu 16.04.4 Thrown From: php-debug package 0.3.2

Stack Trace

Uncaught TypeError: Cannot read property 'length' of undefined

At /home/francesco/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:159

TypeError: Cannot read property 'length' of undefined
    at DbgpInstance.parse (/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:159:58)
    at DbgpInstance.handleData (/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:275:10)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at TCP.onread (net.js:560:20)

Commands

     -5:09.5.0 core:save (input.hidden-input)
     -5:09.1.0 core:backspace (input.hidden-input)
     -5:08.7.0 intentions:highlight (input.hidden-input)
     -5:08.7.0 core:save (input.hidden-input)
     -2:24.6.0 editor:select-to-first-character-of-line (input.hidden-input)
  4x -2:24.2.0 core:backspace (input.hidden-input)
     -2:21.9.0 intentions:highlight (input.hidden-input)
     -2:21.9.0 core:save (input.hidden-input)
     -2:21.5.0 core:move-down (input.hidden-input)
     -2:21.3.0 editor:move-to-first-character-of-line (input.hidden-input)
     -2:19.1.0 markdown-writer:insert-new-line (input.hidden-input)
     -2:19.1.0 docblockr:parse-enter (input.hidden-input)
     -2:19.1.0 editor:newline (input.hidden-input)
     -2:18.1.0 core:backspace (input.hidden-input)
     -2:17.8.0 intentions:highlight (input.hidden-input)
     -2:17.7.0 core:save (input.hidden-input)

Non-Core Packages

atom-debug-ui 1.0.1 
atom-ide-ui 0.11.1 
atom-json-editor 0.4.1 
busy-signal 1.4.3 
city-lights-syntax 1.1.8 
city-lights-ui 1.3.3 
color-picker 2.3.0 
docblockr 0.13.7 
fold-comments 0.6.0 
fold-functions 0.5.0 
git-history 3.3.0 
git-log 0.4.1 
git-plus 7.10.2 
git-time-machine 1.5.9 
highlight-selected 0.13.1 
hyperclick 0.0.0 
ide-json 0.2.1 
ide-php 0.7.14 
intentions 1.1.5 
jackhammer-syntax 1.1.0 
language-apache 1.8.0 
linter 2.2.0 
linter-php 1.5.1 
linter-sass-lint 1.8.3 
linter-ui-default 1.7.1 
markdown-preview-plus 3.0.1 
markdown-writer 2.7.3 
minimap 4.29.8 
minimap-autohider 1.5.4 
minimap-bookmarks 0.4.2 
minimap-cursorline 0.2.0 
minimap-highlight-selected 4.6.1 
my-theme-syntax 0.0.0 
php-debug 0.3.2 
php-ide-serenata 4.0.3 
php-integrator-annotations 1.2.0 
php-integrator-refactoring 1.4.1 
pigments 0.40.2 
platformio-ide-terminal 2.8.1 
pretty-json 2.0.0 
project-manager 3.3.5 
todo-show 2.3.0 
wakatime 7.0.4 
kafoso commented 6 years ago

I'm facing a similar problem with package version 0.3.2 on Windows.

Atom: 1.26.1 x64 OS: Windows 10 (64-bit), Version 1709, OS Build 16299.402 Thrown From: php-debug package 0.3.2

Steps to reproduce:

  1. Configure Xdebug (locally in Atom and remotely in xdebug.ini).
  2. Set breakpoint in Atom (in some script file being hit by the request).
  3. Load website in browser.

Error occurs straight away. The error also occurs on any action (Continue, Step Over, Step In, Step Out, Stop). Only function that seems to be working is Detach.


Error:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at file:///C:/Users/***/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:223:29
    at Parser.<anonymous> (C:\Users\***\.atom\packages\php-debug\node_modules\xml2js\lib\parser.js:303:18)
    at emitOne (events.js:96:13)
    at Parser.emit (events.js:191:7)
    at Parser.exports.Parser.Parser.parseString (C:\Users\***\.atom\packages\php-debug\node_modules\xml2js\lib\parser.js:313:16)
    at Parser.parseString (C:\Users\***\.atom\packages\php-debug\node_modules\xml2js\lib\parser.js:5:59)
    at exports.parseString (C:\Users\***\.atom\packages\php-debug\node_modules\xml2js\lib\parser.js:354:19)
    at DbgpInstance.parseXml (file:///C:/Users/***/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:219:13)
    at DbgpInstance.parse (file:///C:/Users/***/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:196:12)
    at DbgpInstance.handleData (file:///C:/Users/***/.atom/packages/php-debug/lib/engines/dbgp/dbgp-instance.js:275:10)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at TCP.onread (net.js:560:20)

Additionally, Atom reports this issue as already have been reported, as issue #58, but it's really not the same problem. It happens in a different script files and lines - dbgp-instance.js vs dbgp-instance.coffee - although, the file names suggest it might simply be a refactor of Coffee Script to Javascript.

cchamplin commented 6 years ago

Hi all, I apologize this has been a problem since 0.3.0. There were major rewrites and adjustments of the DBGP protocol handling in PHP-Debug to be faster and handler more types of debugging (stdin,stdout). Unfortunately it's been extremely hard for me to get good testing coverage without real world debugging instances.

I've pushed 0.3.3 out and hopefully it'll fix the on going issues, if not I'll continue to be responsive and we'll get point releases out until it's working :)

kafoso commented 6 years ago

Cheers, @cchamplin.

Aforementioned error is gone. However, none of functions work, except for Detach (luckily). I've tried hotkeys (for both "Atom Ide Debugger" and "Php Debug") and the UI buttons (both bottom panel and the popover). Nothing happens. The debugger stops correctly at the first break point encountered, but then nothing happens. Nothing under Context (local variables, etc.) gets populated.

There's also an issue with the newly introduced dependency on the "PHP IDE circus". Everything runs horrendously slowly, to the point where the packages are hindering work processes significantly.

y-morozov commented 6 years ago

This probably can be related with new multi-session feature. Every ajax request gets intercepted, new session is fired and everything stops working. In my app there's a repeating ajax (to check for new data) and every request is displayed as a separate tab in UI.

cchamplin commented 6 years ago

@kafoso Can you enable Xdebug DBGP Protocol Debugging in the settings and then send me a copy of your atom debug log with logging set to verbose and all console lines expanded?

cchamplin commented 6 years ago

v0.3.4 just landed and hopefully the parser issues will finally be resolved. Let me know.

cchamplin commented 6 years ago

@y-morozov I've added a setting in v0.3.4 to disable multi-sessions. There is also now functionality to automatically detach and ignore specific files/paths.

y-morozov commented 6 years ago

@cchamplin Probably it doesn't work.

Here's my test:

  1. checkbox "allow multiple sessions" is unchecked (so this should allow only one session, right?)
  2. test file:
<?php

$a = 1;

header('Content-type: text-plain');

echo 'test';

exit;

I'm setting a breakpoint at first line ($a = 1), start a debugging session and open script in browser. Everything works as expected, execution stops at breakpoint.

Then I return to my browser and reload page several times. Every reload starts separate debugging session, and now my UI is full of debugging tabs.

This is a simple case. In the real project ajax requests from page also get captured.

cchamplin commented 5 years ago

Can you confirm if this is still occurring in 0.3.5?