autocomplete-plus icon indicating copy to clipboard operation
autocomplete-plus copied to clipboard

Cannot read property 'replace' of undefined in certain filetypes

Open tylerFowler opened this issue 8 years ago • 38 comments

Edit by @rsese to add repro steps

  1. Start Atom in safe mode atom --safe
  2. Add _ to Settings > Editor > Non Word Characters
  3. Create a new file
  4. Start typing in the new file

macOS 10.12.6 and Atom 1.25.


I find that in certain file types I get this exception thrown (Atom Beta). So far I've found it reliably does it in git commit message types (invoked by git-plus) and in Go files, but have not seen it with the same version in JS or Java files. It tends to keep throwing this error over and over as I type.

Worth noting this error was definitely not present until the latest Beta update, which included autocomplete-plus version 2.40.2

Atom: 1.25.0-beta0 x64 Electron: 1.7.11 OS: Mac OS X 10.13.3 Thrown From: Atom Core

Stack Trace

Uncaught TypeError: Cannot read property 'replace' of undefined

At /Applications/Atom Beta.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:527

TypeError: Cannot read property 'replace' of undefined
    at AutocompleteManager.getWordCharacterRegex (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:527:72)
    at AutocompleteManager.getPrefix (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:507:43)
    at AutocompleteManager.findSuggestions (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:260:31)

Commands

  2x -0:09.1.0 core:move-down (input.hidden-input)
     -0:07.3.0 editor:delete-to-beginning-of-word (input.hidden-input)
     -0:06.6.0 core:backspace (input.hidden-input)
     -0:05.8.0 editor:delete-to-beginning-of-word (input.hidden-input)
     -0:04.3.0 core:move-up (input.hidden-input)

Non-Core Packages

Was able to reproduce in safe mode

tylerFowler avatar Feb 17 '18 00:02 tylerFowler

I've noticed that this error is not raised when the language-babel package is disabled. I can't tell if it's caused by the language-babel, but I think it would be helpful to post this issue to its issues as well :--)

Third time's the charm.

tuomashatakka avatar Feb 26 '18 15:02 tuomashatakka

This is kind of weird but after the latest update to Atom my config was somehow completely blown away and now I'm no longer getting this error? Will close for now and reopen if I'm able to reproduce again.. And if it does crop up again I'll try disabling language-babel thanks for the tip @tuomashatakka

tylerFowler avatar Feb 27 '18 17:02 tylerFowler

I'm also on atom beta and have the same issue on plain text files, the version I'm using is 1.25.0-beta3.

It's not a babel issue for me as it also happens on safe mode.

[Enter steps to reproduce:]

  1. Open atom in safe mode
  2. It opens with an empty plain text editor
  3. Type anything
  4. Error apppears

Atom: 1.25.0-beta3 x64 Electron: 1.7.11 OS: Microsoft Windows 10 Home Thrown From: Atom Core

Stack Trace

Uncaught TypeError: Cannot read property 'replace' of undefined

At C:\ProgramData\iagoqo\atom\app-1.25.0-beta3\resources\app\node_modules\autocomplete-plus\lib\autocomplete-manager.js:527

TypeError: Cannot read property 'replace' of undefined
    at AutocompleteManager.getWordCharacterRegex (C:/ProgramData/iaaggooqqoo/atom/app-1.25.0-beta3/resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:527:72)
    at AutocompleteManager.getPrefix (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:507:43)
    at AutocompleteManager.findSuggestions (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:260:31)
    at AutocompleteManager.requestNewSuggestions (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:704:18)
    at AutocompleteManager.showOrHideSuggestionListForBufferChanges (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:770:18)
    at Function.module.exports.Emitter.simpleDispatch (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/event-kit/lib/emitter.js:25:20)
    at Emitter.module.exports.Emitter.emit (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/event-kit/lib/emitter.js:141:34)
    at TextBuffer.module.exports.TextBuffer.emitDidChangeTextEvent (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/text-buffer/lib/text-buffer.js:1748:32)
    at TextBuffer.module.exports.TextBuffer.transact (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/text-buffer/lib/text-buffer.js:975:18)
    at TextEditor.transact (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/src/text-editor.js:1839:30)
    at mergeIntersectingSelections (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/src/text-editor.js:1386:25)
    at TextEditor.mergeSelections (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/src/text-editor.js:3252:26)
    at TextEditor.mergeIntersectingSelections (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/src/text-editor.js:3223:42)
    at TextEditor.mutateSelectedText (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/src/text-editor.js:1385:23)
    at TextEditor.insertText (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/src/text-editor.js:1349:31)
    at TextEditor.object.(anonymous function) [as insertText] (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/node_modules/underscore-plus/lib/underscore-plus.js:77:33)
    at TextEditorComponent.didTextInput (C:/ProgramData/iagoqo/atom/app-1.25.0-beta3/resources/app/src/text-editor-component.js:1654:30)

Commands

  2x -1:45.3.0 editor:delete-to-previous-word-boundary (input.hidden-input)

Non-Core Packages


Edit: So far I've found the issue on plain text and JSON files.

iagoqo avatar Mar 14 '18 13:03 iagoqo

@iagoqo have you tried clearing saved state (make sure to save any unsaved data first)?

https://flight-manual.atom.io/hacking-atom/sections/debugging/#clearing-saved-state

rsese avatar Mar 15 '18 21:03 rsese

I have the same issue only for R files. Unfortunately, clearing the saved state didn't help.

edrubin avatar Mar 16 '18 14:03 edrubin

I too have the same issue for at least Ruby and plain text files. HTML works fine.

BojanOro avatar Mar 16 '18 15:03 BojanOro

@edrubin @BojanOro is this in safe mode as well?

rsese avatar Mar 16 '18 21:03 rsese

@rsese indeed, safe mode doesn't help. Also attempted to clear the saved state to no avail.

Atom : 1.25.0 Electron: 1.7.11 OS: MacOS 10.13.1

Stack Trace:

TypeError: Cannot read property 'replace' of undefined
    at AutocompleteManager.getWordCharacterRegex (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:527:72)
    at AutocompleteManager.getPrefix (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:507:43)
    at AutocompleteManager.findSuggestions (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:260:31)
    at AutocompleteManager.requestNewSuggestions (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:704:18)
    at AutocompleteManager.showOrHideSuggestionListForBufferChanges (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:770:18)
    at Function.module.exports.Emitter.simpleDispatch (/Applications/Atom.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:25:20)
    at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:141:34)
    at TextBuffer.module.exports.TextBuffer.emitDidChangeTextEvent (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:1748:32)
    at TextBuffer.module.exports.TextBuffer.transact (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:975:18)
    at TextEditor.transact (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:1839:30)
    at mergeIntersectingSelections (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:1386:25)
    at TextEditor.mergeSelections (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:3252:26)
    at TextEditor.mergeIntersectingSelections (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:3223:42)
    at TextEditor.mutateSelectedText (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:1385:23)
    at TextEditor.insertText (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:1349:31)
    at TextEditor.object.(anonymous function) [as insertText] (/Applications/Atom.app/Contents/Resources/app/node_modules/underscore-plus/lib/underscore-plus.js:77:33)
    at TextEditorComponent.didTextInput (/Applications/Atom.app/Contents/Resources/app/src/text-editor-component.js:1654:30)

BojanOro avatar Mar 16 '18 21:03 BojanOro

Do you have steps to reproduce so we can give it a try @BojanOro?

rsese avatar Mar 16 '18 22:03 rsese

  1. Open a new file
  2. Start typing. Literally a single character will throw an exception.

BojanOro avatar Mar 16 '18 22:03 BojanOro

@BojanOro I cannot reproduce by following those steps.

Is there anything more specific you can give, such as what config settings you have for autocomplete-plus? Additionally, check for scope specific settings under each language.

Aerijo avatar Mar 16 '18 23:03 Aerijo

I have the same issue:

/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:527
Hide Stack Trace
TypeError: Cannot read property 'replace' of undefined
    at AutocompleteManager.getWordCharacterRegex (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:527:72)
    at AutocompleteManager.getPrefix (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:507:43)
    at AutocompleteManager.findSuggestions (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:260:31)
    at AutocompleteManager.requestNewSuggestions (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:704:18)
    at AutocompleteManager.showOrHideSuggestionListForBufferChanges (/Applications/Atom.app/Contents/Resources/app/node_modules/autocomplete-plus/lib/autocomplete-manager.js:770:18)
    at Function.module.exports.Emitter.simpleDispatch (/Applications/Atom.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:25:20)
    at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:141:34)
    at TextBuffer.module.exports.TextBuffer.emitDidChangeTextEvent (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:1748:32)
    at TextBuffer.module.exports.TextBuffer.transact (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:975:18)
    at TextEditor.transact (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:1839:30)
    at mergeIntersectingSelections (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:1386:25)
    at TextEditor.mergeSelections (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:3252:26)
    at TextEditor.mergeIntersectingSelections (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:3223:42)
    at TextEditor.mutateSelectedText (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:1385:23)
    at TextEditor.insertText (/Applications/Atom.app/Contents/Resources/app/src/text-editor.js:1349:31)
    at TextEditor.object.(anonymous function) [as insertText] (/Applications/Atom.app/Contents/Resources/app/node_modules/underscore-plus/lib/underscore-plus.js:77:33)
    at TextEditorComponent.didTextInput (/Applications/Atom.app/Contents/Resources/app/src/text-editor-component.js:1654:30)

I have Python Executable Paths and Extra Paths For Packages set.

@tylerFowler What do you mean by:

This is kind of weird but after the latest update to Atom my config was somehow completely blown away and now I'm no longer getting this error?

Can you please reopen this issue? It seems it is still very present for some users.

drorata avatar Mar 19 '18 08:03 drorata

@drorata Are you able to provide steps to reproduce this? So far the suggested steps of:

  1. Open an editor
  2. Type something

Haven't been able to be reproduced by anyone, so there must be something missing from them.

Can somebody who is experiencing this try Resetting to Factory Defaults temporarily to see if they still see this on a clean profile?

Arcanemagus avatar Mar 19 '18 17:03 Arcanemagus

I apologize for the late reply...

I've reset to factory defaults and the issues goes away for me. I have done very little customization previously so I'm not entirely sure what was reset that made autocomplete work for me. When I have some time I'll look through my previous config and see if I can find the root cause.

edit: Is there anything I should be looking for between my two .atom files (working and not working)? I've installed the same plugins, and as far as I know they're the same now and I don't have the issue coming back.

BojanOro avatar Mar 19 '18 17:03 BojanOro

It's likely that any relevant difference would be in the config.cson, but as we haven't been able to replicate this I'm just guessing 😉. I'm glad to hear that that worked for you!

Arcanemagus avatar Mar 19 '18 17:03 Arcanemagus

For other folks reporting the error, can you also try temporarily resetting to factory defaults and confirm if the error clears up for you? It might be interesting to see your config.cson files too.

rsese avatar Mar 19 '18 17:03 rsese

Steps to replicate:

  1. Edit Editor > Non Word Characters - add an underscore _ to the end of the string (ie /\()"':,.;<>~!@#$%^&*|+=[]{}`?-…_)
  2. Attempt to type

BojanOro avatar Mar 19 '18 17:03 BojanOro

I can confirm that adding _ to the Non-Word characters list causes this, thanks for finding that @BojanOro!

Arcanemagus avatar Mar 19 '18 17:03 Arcanemagus

Glad to see this one gained some traction.. sort of forgot about it after it was "fixed" for me, thanks @Arcanemagus for reopening.

tylerFowler avatar Mar 19 '18 20:03 tylerFowler

I think I've narrowed down the source of the problem, but I've never actually worked with Atom's packages so I'm hesitant to fix it myself; instead I hope that I can make somebody else save a few minutes of time tracking this down.

In get-additional-word-characters.js when you do not have _ as a non-word character the result returned is "undefined_" (as in, a string). Adding _ as a non-word character means the _ is no longer concatenated and result is returned as undefined (as in, undefined). Obviously, replace in AutocompleteManager.getWordCharacterRegex will not work on undefined.

result should probably be set to an empty string if atom.config.get('autocomplete.extraWordCharacters', {scope: scopeDescriptor}) returns undefined, this way we never return undefined.

BojanOro avatar Mar 20 '18 03:03 BojanOro