docblockr icon indicating copy to clipboard operation
docblockr copied to clipboard

Uncaught TypeError: Cannot read property '1' of null with PHP Syntax Error

Open codazoda opened this issue 8 years ago • 18 comments

Steps to reproduce:

Type the following code and save it into a file called bug.php.

<?php

class Example {

  private function get(number) {
    return false;
  }

}

Move just above the function and type /** and press enter. You'll get the error.

Notice that my private function has a syntax error. It should be $number instead of number, but it would be awesome if docblockr didn't throw an uncaught error here.

Atom Version: 1.4.2 System: Mac OS X 10.11.1 Thrown From: docblockr package, v0.7.3

Stack Trace

Uncaught TypeError: Cannot read property '1' of null

At /Users/joel/.atom/packages/docblockr/lib/languages/php.js:67

TypeError: Cannot read property '1' of null
    at DocsParser.PhpParser.get_arg_name (/Users/joel/.atom/packages/docblockr/lib/languages/php.js:67:19)
    at DocsParser.parse_args (/Users/joel/.atom/packages/docblockr/lib/docsparser.js:265:48)
    at DocsParser.format_function (/Users/joel/.atom/packages/docblockr/lib/docsparser.js:130:32)
    at DocsParser.parse (/Users/joel/.atom/packages/docblockr/lib/docsparser.js:44:37)
    at DocBlockrAtom.module.exports.DocBlockrAtom.parse_command (/Users/joel/.atom/packages/docblockr/lib/docblockr-worker.js:279:29)
    at atom-workspace.<anonymous> (/Users/joel/.atom/packages/docblockr/lib/docblockr-worker.js:75:16)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:260:29)
    at /Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:536:16)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:359:22)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeydown (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:97:36)
    at HTMLDocument.<anonymous> (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:3:61)

Commands

     -3:57.1.0 core:move-up (atom-text-editor.editor.is-focused)
     -3:56.2.0 core:move-down (atom-text-editor.editor.is-focused)
 26x -3:55.6.0 core:move-left (atom-text-editor.editor.is-focused)
  5x -3:53.9.0 core:select-left (atom-text-editor.editor.is-focused)
  3x -3:51.3.0 core:backspace (atom-text-editor.editor.is-focused.autocomplete-active)
     -3:49.4.0 core:move-up (atom-text-editor.editor.is-focused)
     -3:47.6.0 docblockr:parse-enter (atom-text-editor.editor.is-focused)
     -0:04.6.0 editor:select-to-first-character-of-line (atom-text-editor.editor.is-focused)
  3x -0:04.1.0 core:backspace (atom-text-editor.editor.is-focused)
     -0:02.4.0 docblockr:parse-enter (atom-text-editor.editor.is-focused)
     -0:02.4.0 editor:newline (atom-text-editor.editor.is-focused)
     -0:01.7.0 docblockr:parse-tab (atom-text-editor.editor.is-focused)
     -0:01.7.0 snippets:next-tab-stop (atom-text-editor.editor.is-focused)
     -0:01.7.0 snippets:expand (atom-text-editor.editor.is-focused)
     -0:01.7.0 editor:indent (atom-text-editor.editor.is-focused)
     -0:00.5.0 docblockr:parse-enter (atom-text-editor.editor.is-focused)

Config

{
  "core": {},
  "docblockr": {}
}

Installed Packages

# User
docblockr, v0.7.3

# Dev
No dev packages

codazoda avatar Feb 04 '16 03:02 codazoda

You forgot the dollar prefix on the variable name. When using type declaration arguments it highlight as error but it doesn't prompt any error and build the comment correctly.

lysz210 avatar Feb 15 '16 23:02 lysz210

For me in php script, you insert a js script and you would add a comment on it :

<?php echo "poooo"; ?>
<script>
/**{enter}{crack-bug}
function jsfunciton(){
....
}
</script>

madvik avatar Feb 18 '16 13:02 madvik

My bug report is specifically about the behavior when you have a typo that results in a syntax error. Probably a low priority as a result.

codazoda avatar Feb 18 '16 14:02 codazoda

When i have the bug, Atom redirected me to this bug, the same error code.

madvik avatar Feb 18 '16 14:02 madvik

I have the same issue for valid code in C/C++

  1. Write a function declaration with a reference or pointer and do not name the parameter
  2. Something like void foo(int&); or void foo(int*);
  3. Try to document it with /**

Atom Version: 1.3.1 System: "Arch Linux" Thrown From: docblockr package, v0.7.3

Stack Trace

Uncaught TypeError: Cannot read property '1' of null

At /home/matthew/.atom/packages/docblockr/lib/languages/cpp.js:64

TypeError: Cannot read property '1' of null
    at DocsParser.CppParser.get_arg_name (/home/matthew/.atom/packages/docblockr/lib/languages/cpp.js:64:19)
    at DocsParser.parse_args (/home/matthew/.atom/packages/docblockr/lib/docsparser.js:265:48)
    at DocsParser.CppParser.parse_args (/home/matthew/.atom/packages/docblockr/lib/languages/cpp.js:49:44)
    at DocsParser.format_function (/home/matthew/.atom/packages/docblockr/lib/docsparser.js:130:32)
    at DocsParser.parse (/home/matthew/.atom/packages/docblockr/lib/docsparser.js:44:37)
    at DocBlockrAtom.module.exports.DocBlockrAtom.parse_command (/home/matthew/.atom/packages/docblockr/lib/docblockr-worker.js:279:29)
    at atom-workspace.<anonymous> (/home/matthew/.atom/packages/docblockr/lib/docblockr-worker.js:75:16)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/usr/share/atom/resources/app.asar/src/command-registry.js:260:29)
    at /usr/share/atom/resources/app.asar/src/command-registry.js:3:61
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/usr/share/atom/resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:536:16)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/usr/share/atom/resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:359:22)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeydown (/usr/share/atom/resources/app.asar/src/window-event-handler.js:97:36)
    at HTMLDocument.<anonymous> (/usr/share/atom/resources/app.asar/src/window-event-handler.js:3:61)

Commands

     -0:29 editor:newline (atom-text-editor.editor.is-focused)
  2x -0:27.4.0 docblockr:parse-enter (atom-text-editor.editor.is-focused)
     -0:23.1.0 editor:select-to-first-character-of-line (atom-text-editor.editor.is-focused)
     -0:22.7.0 core:delete (atom-text-editor.editor.is-focused)
     -0:21 docblockr:parse-enter (atom-text-editor.editor.is-focused)
     -0:04.8.0 editor:select-to-first-character-of-line (atom-text-editor.editor.is-focused)
     -0:04.5.0 core:delete (atom-text-editor.editor.is-focused)
  2x -0:03.9.0 core:backspace (atom-text-editor.editor.is-focused)
     -0:02.5.0 core:save (atom-text-editor.editor.is-focused)
     -0:02.0 docblockr:parse-enter (atom-text-editor.editor.is-focused)
     -0:02.0 editor:newline (atom-text-editor.editor.is-focused)
     -0:01.3.0 snippets:next-tab-stop (atom-text-editor.editor.is-focused)
     -0:01.3.0 snippets:expand (atom-text-editor.editor.is-focused)
     -0:01.3.0 docblockr:parse-tab (atom-text-editor.editor.is-focused)
     -0:01.3.0 editor:indent (atom-text-editor.editor.is-focused)
     -0:00.3.0 docblockr:parse-enter (atom-text-editor.editor.is-focused)

Config

{
  "core": {
    "themes": [
      "atom-material-ui",
      "one-light-syntax"
    ]
  }
}

Installed Packages

# User
atom-material-ui, v0.8.1
docblockr, v0.7.3
file-icons, v1.6.14
hyperclick, v0.0.35
language-cpp14, v0.6.0
language-latex, v0.6.1
language-squirrel, v0.4.3
linter, v1.11.3
linter-javac, v1.5.0
linter-jshint, v2.0.2
pdf-view, v0.39.0

# Dev
No dev packages

mattiekat avatar Mar 04 '16 05:03 mattiekat

I have seen this too. Is this plugin abandoned?

jordwalke avatar Mar 28 '16 21:03 jordwalke

I'm getting this error when I call the WrapLines command.

jasperkennis avatar Apr 28 '16 08:04 jasperkennis

Just got this error while documenting a C++ member function declaration.

docblockr version: 0.8.4

The snippet of code causing the issue:

class DukThread {
public:
    DukThread ();

    /** <- crash here */
    void eval (const std::string& script,
               const boost::function<void (std::string&)>& onSuccess,
               const boost::function<void (std::string&)>& onError = [](std::string& result){ std::cerr << "DukThread " << result << std::endl; });
...
}

StefanHamminga avatar Aug 26 '16 19:08 StefanHamminga

I'd also receive this error for C++ header code on a function using un-named parameters.

sgtcoolguy avatar Sep 14 '16 17:09 sgtcoolguy

This error appears in various cases, but Atom sends everyone to this issue. If you see this error, Atom sends you to this page and your problem is not yet covert: please open a new issue and describe the behavior that lead to the error.

Problems described in this issue

  • [ ] Error when commenting a function with syntax error by @codazoda I can reproduce this and agree with you: this shouldn't lead to an error, but it's low prio.
  • [ ] Error when commenting JS script inside PHP by @madvik I can't reproduce this and assume it was fixed in the meantime. If that's not the case, please provide more information.
  • [x] Error with unnamed function parameters in C++ (e.g. void foo(int&)) by @Eadword and perhaps @sgtcoolguy (..?) I can reproduce this. PR #174 addresses this problem.
  • [ ] Error when calling WrapLines by @jasperkennis Sorry I can't reproduce this and have no starting point for debugging this error. Please provide more information.
  • [ ] Error when commenting crazy C++ code by @StefanHamminga I have to admit I have no idea what your code does; my C++ skills are way to limited for that, but I could reduce your code to this void test (foo<void (bar&)> baz); and still reproduce the error. The problem is this bar&. Maybe #174 will resolve this too.

Edit: I thought blocking an Issue would limit access to participants but it removes access for all users, so I won't do that.

MoritzKn avatar Oct 06 '16 14:10 MoritzKn

#222 addresses the WrapLines error.

MoritzKn avatar Oct 06 '16 15:10 MoritzKn

The Error with unnamed function parameters in C++ was fixed by @jeremyvii. Version v0.8.6 released the fix.

MoritzKn avatar Oct 06 '16 16:10 MoritzKn

The Wrap Lines Error was fixed by #222

MoritzKn avatar Oct 06 '16 17:10 MoritzKn

This did not seem to fix it for me. I'm still seeing this same error, even after upgrading.

jordwalke avatar Nov 13 '16 08:11 jordwalke

@jordwalke As described in my comment above, this issue describes multiple errors. Some off them got fixed, some didn't. What particular problem did you experience?

MoritzKn avatar Nov 13 '16 15:11 MoritzKn

The wrap lines error still occurs with the same message in the OP.

jordwalke avatar Nov 14 '16 01:11 jordwalke

@jordwalke This problem is not fixed yet. See my comment.

MoritzKn avatar Nov 14 '16 12:11 MoritzKn

Still happens to this day.

H-s-O avatar Aug 09 '18 14:08 H-s-O