danielbayley / atom-modular-snippets

:atom: A modular solution to snippets in @Atom.
https://atom.io/packages/modular-snippets
MIT License
9 stars 4 forks source link

Uncaught TypeError: Cannot read property 'startsWith' of undefined #3

Open Ankiewicz opened 8 years ago

Ankiewicz commented 8 years ago

[Enter steps to reproduce below:]

  1. ...
  2. ...

Atom Version: 1.8.0 System: Mac OS X 10.10.5 Thrown From: modular-snippets package, v0.1.2

Stack Trace

Uncaught TypeError: Cannot read property 'startsWith' of undefined

At /Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:1002

TypeError: Cannot read property 'startsWith' of undefined
    at /Users/jankiewicz/.atom/packages/modular-snippets/index.coffee:49:22
    at Function.module.exports.Emitter.simpleDispatch (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/event-kit/lib/emitter.js:25:14)
    at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/event-kit/lib/emitter.js:125:28)
    at TextBuffer.module.exports.TextBuffer.saveAs (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:1113:27)
    at TextEditor.module.exports.TextEditor.saveAs (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:666:26)
    at Pane.module.exports.Pane.saveItemAs (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:742:16)
    at Pane.module.exports.Pane.saveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:726:21)
    at Pane.module.exports.Pane.saveActiveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:701:19)
    at Workspace.module.exports.Workspace.saveActivePaneItem (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace.js:684:35)
    at atom-workspace.commandRegistry.add.core:save (/Applications/Atom.app/Contents/Resources/app.asar/src/register-default-commands.js:214:32)
    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:580:16)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:388:22)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:98:36)
    at HTMLDocument.<anonymous> (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:3:61)

Commands

     -0:23.7.0 core:save (atom-text-editor.editor.is-focused)

Config

{
  "core": {
    "disabledPackages": [
      "linter-jshint"
    ]
  }
}

Installed Packages

# User
atom-beautify, v0.29.10
atom-bootstrap4, v1.4.0
emmet, v2.4.3
highlight-selected, v0.11.2
jade-beautify, v0.1.5
javascript-snippets, v1.2.1
language-ejs, v0.2.0
language-pug, v0.0.17
linter, v1.11.14
linter-eslint, v7.2.4
linter-htmlhint, v1.3.0
linter-scss-lint, v3.0.4
modular-snippets, v0.1.2
personal-snippets, vundefined
pigments, v0.31.2
pretty-json, v1.4.4
react, v0.15.0
standard-formatter, v2.0.1
terminal-plus, v0.14.5

# Dev
No dev packages
danielbayley commented 8 years ago

personal-snippets, vundefined

@Ankiewicz I wonder if this might have anything to do with it?

Ankiewicz commented 8 years ago

Thank you, I deleted the folder from packages and it works without throwing an error. This was my attempting to load the snippets without your package.

THANK YOU!!

danielbayley commented 8 years ago

@Ankiewicz So that was the cause or not? This package loads your snippets from ATOM_HOME/snippets so just move them into there…

Ankiewicz commented 8 years ago

Yes it appears to have been.

Ankiewicz commented 8 years ago

Okay, as soon as I said yes, it showed up again, of course

Ankiewicz commented 8 years ago
screen shot 2016-08-02 at 9 32 50 am screen shot 2016-08-02 at 9 33 10 am

Not sure if these help at all. Please let me know if there is anything else I can do to help resolve the bug.

Could it be two different packages conflicting?

danielbayley commented 8 years ago

Okay, as soon as I said yes, it showed up again, of course

Always the way… 😄

@Ankiewicz Just looking at this… Iv’e actually refactored the code a bit since the last update on my local copy so will push an update that should/might correct this (it makes heavier use of the ? existential operator…)

Could it be two different packages conflicting?

I don’t think so, but do you still have that personal-snippets package running?

The error is thrown from this line so it’s not picking up @project (which is just atom.project.getPaths()[0]), not sure why… Is it actually loading your snippets from ATOM_HOME/snippets and/or you local project snippets?

Ankiewicz commented 8 years ago

I don’t think so, but do you still have that personal-snippets package running? No I deleted the folder. I am still using the snippets, but that attempt of creating my own package, I dropped it.

I created a folder "snippets" in the atom file and it's working from there.(attached image of folder structure)

screen shot 2016-08-08 at 12 46 56 pm
Ankiewicz commented 8 years ago

also, wanted to note it only occurs when I save the file.

guerrero commented 8 years ago

Same problem here, these are the steps I followed to reproduce the bug:

  1. Open folder in Atom
  2. Create new folder
  3. Create new file using Application: New File command
  4. Save it in the new folder I've created before

After the step number 4 the error shows up. It seems that path is undefined for files created using Application: New File and it produces that startsWith can be reached because path is undefined. A simple workaround could be check if path exists before execute that part of the code.

cristianPerez commented 5 years ago

This is the best config. https://gist.github.com/radiovisual/7c27e5a1d0f7aa56e0e3922c98e19ffc