bsegraves / custom-folds

Atom plugin for defining custom markers for foldable regions.
MIT License
24 stars 9 forks source link

Uncaught TypeError: Cannot read property 'getLineCount' of undefined #28

Closed derrickwheals closed 7 years ago

derrickwheals commented 7 years ago

[Enter steps to reproduce:]

  1. ...
  2. ...

Atom: 1.17.0 ia32 Electron: 1.3.15 OS: Microsoft Windows 10 Enterprise Thrown From: custom-folds package 1.9.3

Stack Trace

Uncaught TypeError: Cannot read property 'getLineCount' of undefined

At C:\Users\derrick.wheals\.atom\packages\custom-folds\lib\index.js:244

TypeError: Cannot read property 'getLineCount' of undefined
    at Object.foldAll (/packages/custom-folds/lib/index.js:244:28)
    at /packages/custom-folds/lib/index.js:207:127
    at Function.module.exports.Emitter.simpleDispatch (~/AppData/Local/atom/app-1.17.0/resources/app/node_modules/event-kit/lib/emitter.js:25:1)
    at Emitter.module.exports.Emitter.emit (~/AppData/Local/atom/app-1.17.0/resources/app/node_modules/event-kit/lib/emitter.js:141:1)
    at TokenizedBuffer.module.exports.TokenizedBuffer.markTokenizationComplete (~/AppData/Local/atom/app-1.17.0/resources/app/src/tokenized-buffer.js:231:1)
    at TokenizedBuffer.module.exports.TokenizedBuffer.tokenizeNextChunk (~/AppData/Local/atom/app-1.17.0/resources/app/src/tokenized-buffer.js:225:1)
    at ~/AppData/Local/atom/app-1.17.0/resources/app/src/tokenized-buffer.js:185:1
    at ~/AppData/Local/atom/app-1.17.0/resources/app/node_modules/underscore/underscore.js:666:1

Commands

Non-Core Packages

atom-beautify 0.29.24 
atom-material-syntax 1.0.6 
atom-material-syntax-dark 1.0.0 
atom-material-syntax-light 0.4.6 
atom-material-ui 2.0.3 
atom-monokai 0.10.9 
atom-python-run 0.7.3 
atom-touch-events 0.23.0 
autocomplete-python 1.8.63 
custom-folds 1.9.3 
dark-flat-ui 1.2.4 
date 1.2.2 
file-icons 2.1.5 
flex-tool-bar 0.12.0 
fold-lines 0.2.2 
highlight-line 0.12.0 
highlight-selected 0.13.1 
hyperclick 0.0.40 
hyperlink-hyperclick 1.3.4 
imdone-atom 2.2.6 
intellij-darcula-syntax 1.0.11 
language-gherkin 1.0.4 
language-markdown 0.22.0 
markdown-pdf 1.5.0 
markdown-scroll-sync 2.1.2 
markdown-toc 0.4.2 
markdown-writer 2.6.5 
monokai 0.24.0 
monokai-seti 0.7.0 
nucleus-dark-ui 0.12.1 
one-dark-atom 1.3.0 
one-o-eight-syntax 0.28.2 
pdf-view 0.58.0 
pen-paper-coffee-syntax 0.14.9 
pinned-tabs 1.0.3 
scratch 1.2.0 
seti-ui 1.8.0 
slack-ui 0.8.0 
sort-lines 0.14.0 
tasks 2.6.6 
todo-show 1.11.0 
tool-bar 1.1.0 
tool-bar-almighty 0.8.2 
tool-bar-main 0.0.10 
tool-bar-markdown-writer 0.2.0 
Writer 0.1.0 
Zen 0.16.4 
FlurinArner commented 7 years ago

I'm getting the same error since 1-2 days. Don't know how to reproduce on an unaffected system, but it happens every time I open a new file (any file, with or without custom-fold selectors). It does however disappear, if I deselect "Auto fold on file open?" in the custom-folds settings.

My system

Atom: 1.17.0 x64 Electron: 1.3.15 OS: Mac OS X 10.12.3 Thrown From: custom-folds package 1.9.3

Commands

     -8:33 tree-view:toggle (input.hidden-input)
bsegraves commented 7 years ago

Thanks! I've been buried at work lately but I'll try and review this today.

FlurinArner commented 7 years ago

Don't worry, I can get that too with work =)

I'm looking through it a bit, and found out that atom.workspace.getActiveTextEditor() returns "undefined".

I also noticed that the error does NOT pop up, when a file is actually opened. So actually the error shows up only when a file is "looked at quickly", and the title stays in italics. Don't know how to better describe it =) It's called Preview Tabs or Pending Pane Items

FlurinArner commented 7 years ago

This seems to be still a bug in the atom-tab-preview package. I didn't dig further into it, but did a quick hack for myself, to only give me a warning (that disappears). I added the following code at .atom/packages/custom-folds/lib/index.js:243:3, within the fold-all() method, right after CustomFolds._getOptions();

const { editor, commentChars, areCommentsRequired, prefixes, postfixes } = CustomFolds._getOptions();

// FLU: Added code for Debugging
// PROBLEM: getActiveTextEditor() returns "undefined" with *Pending Pane Items*
// TODO: Fix "Auto-fold on file open?" with *Pending Pane Items*, by having it return something real..?
if(!editor) {
    atom.notifications.addWarning(`Editor is not defined in the Pending Pane Item, as atom.workspace.getActiveTextEditor() = ${atom.workspace.getActiveTextEditor()}. Not auto-folding within Pending Pane Items.`);
    return;
}

That's it for today =) Do you want me to push the changes to somewhere? Or you might want to implement the actual correction of the bug.. If it bothers me, I'll go further into the rabbit's hole and maybe report the bug with the atom-tab-preview team.

bsegraves commented 7 years ago

Thanks, the repro steps were extremely helpful! Fixed in 1.9.4.

FlurinArner commented 7 years ago

And now it even folds while a file is viewed as a Pending Pane Item! Fantastic ;-) Keep up the good work with this great package