federomero / pretty-json

Atom plugin. Format JSON documents.
MIT License
94 stars 23 forks source link

Uncaught TypeError: Cannot read property 'getGrammar' of undefined #55

Closed GHLeader closed 6 years ago

GHLeader commented 8 years ago

[Enter steps to reproduce below:]

  1. ...
  2. ...

Atom Version: 1.9.0 System: Mac OS X 10.11.4 Thrown From: pretty-json package, v1.5.0

Stack Trace

Uncaught TypeError: Cannot read property 'getGrammar' of undefined

At /Users/wangguohua/.atom/packages/pretty-json/index.coffee:68

TypeError: Cannot read property 'getGrammar' of undefined
    at Object.formatter.doEntireFile (/Users/wangguohua/.atom/packages/pretty-json/index.coffee:68:12)
    at Object.PrettyJSON.prettify (/Users/wangguohua/.atom/packages/pretty-json/index.coffee:94:18)
    at atom-workspace.atom.commands.add.pretty-json:prettify (/Users/wangguohua/.atom/packages/pretty-json/index.coffee:124:10)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/src/command-registry.js:260:29)
    at /Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
    at CommandPaletteView.module.exports.CommandPaletteView.confirmed (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/node_modules/command-palette/lib/command-palette-view.js:183:32)
    at CommandPaletteView.module.exports.SelectListView.confirmSelection (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/node_modules/atom-space-pen-views/lib/select-list-view.js:338:21)
    at space-pen-div.atom.commands.add.core:confirm (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/node_modules/atom-space-pen-views/lib/select-list-view.js:109:19)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/src/command-registry.js:260:29)
    at /Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:580:16)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:388:22)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:98:36)
    at HTMLDocument.<anonymous> (/Users/wangguohua/Downloads/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:3:61)

Commands

     -0:13.2.0 command-palette:toggle (atom-workspace.workspace.scrollbars-visible-always.theme-one-dark-syntax.theme-one-dark-ui)
  2x -0:01.8.0 core:move-down (atom-text-editor.editor.mini.is-focused)
     -0:00.9.0 core:move-up (atom-text-editor.editor.mini.is-focused)
     -0:00.1.0 core:confirm (atom-text-editor.editor.mini.is-focused)
     -0:00.1.0 pretty-json:prettify (atom-workspace.workspace.scrollbars-visible-always.theme-one-dark-syntax.theme-one-dark-ui)

Config

{
  "core": {}
}

Installed Packages

# User
pretty-json, v1.5.0 (active)
atom-dark-syntax, v0.27.0 (inactive)
atom-dark-ui, v0.51.0 (inactive)
atom-light-syntax, v0.28.0 (inactive)
atom-light-ui, v0.43.0 (inactive)
base16-tomorrow-dark-theme, v1.1.0 (inactive)
base16-tomorrow-light-theme, v1.1.1 (inactive)
one-dark-ui, v1.3.2 (active)
one-light-ui, v1.3.2 (inactive)
one-dark-syntax, v1.2.0 (active)
one-light-syntax, v1.2.0 (inactive)
solarized-dark-syntax, v1.0.2 (inactive)
solarized-light-syntax, v1.0.2 (inactive)
about, v1.5.2 (active)
archive-view, v0.61.1 (active)
autocomplete-atom-api, v0.10.0 (active)
autocomplete-css, v0.11.1 (active)
autocomplete-html, v0.7.2 (active)
autocomplete-plus, v2.31.0 (active)
autocomplete-snippets, v1.11.0 (active)
autoflow, v0.27.0 (inactive)
autosave, v0.23.1 (active)
background-tips, v0.26.0 (active)
bookmarks, v0.41.0 (active)
bracket-matcher, v0.82.1 (active)
command-palette, v0.38.0 (active)
deprecation-cop, v0.54.1 (active)
dev-live-reload, v0.47.0 (active)
encoding-selector, v0.22.0 (active)
exception-reporting, v0.38.1 (active)
fuzzy-finder, v1.3.0 (active)
git-diff, v1.1.0 (active)
find-and-replace, v0.198.0 (inactive)
go-to-line, v0.31.0 (active)
grammar-selector, v0.48.1 (active)
image-view, v0.58.0 (active)
incompatible-packages, v0.26.1 (active)
keybinding-resolver, v0.35.0 (active)
line-ending-selector, v0.5.0 (active)
link, v0.31.1 (inactive)
markdown-preview, v0.158.0 (active)
metrics, v0.53.1 (active)
notifications, v0.64.1 (active)
open-on-github, v1.2.0 (inactive)
package-generator, v1.0.0 (inactive)
settings-view, v0.238.0 (active)
snippets, v1.0.2 (active)
spell-check, v0.67.1 (active)
status-bar, v1.4.0 (active)
styleguide, v0.46.0 (active)
symbols-view, v0.113.0 (inactive)
tabs, v0.98.0 (active)
timecop, v0.33.1 (active)
tree-view, v0.208.0 (active)
update-package-dependencies, v0.10.0 (active)
welcome, v0.34.0 (active)
whitespace, v0.32.2 (active)
wrap-guide, v0.38.1 (active)
language-c, v0.52.1 (active)
language-clojure, v0.21.0 (active)
language-coffee-script, v0.47.0 (active)
language-csharp, v0.12.1 (active)
language-css, v0.36.2 (active)
language-gfm, v0.86.0 (active)
language-git, v0.13.0 (active)
language-go, v0.42.0 (active)
language-html, v0.44.1 (active)
language-hyperlink, v0.16.0 (active)
language-java, v0.22.0 (active)
language-javascript, v0.119.0 (active)
language-json, v0.18.0 (active)
language-less, v0.29.3 (active)
language-make, v0.22.2 (active)
language-mustache, v0.13.0 (active)
language-objective-c, v0.15.1 (active)
language-perl, v0.35.0 (active)
language-php, v0.37.0 (active)
language-property-list, v0.8.0 (active)
language-python, v0.45.0 (active)
language-ruby, v0.68.5 (active)
language-ruby-on-rails, v0.25.0 (active)
language-sass, v0.52.0 (active)
language-shellscript, v0.22.3 (active)
language-source, v0.9.0 (active)
language-sql, v0.21.1 (active)
language-text, v0.7.1 (active)
language-todo, v0.28.0 (active)
language-toml, v0.18.0 (active)
language-xml, v0.34.8 (active)
language-yaml, v0.26.0 (active)

# Dev
No dev packages
liry commented 6 years ago

Why's this issue closed? I just got the same exception when I tried to prettify simple JSON:

Atom: 1.27.2 x64 Electron: 1.7.15 OS: Mac OS X 10.12.6 Thrown From: pretty-json package 2.0.0

Stack Trace

Uncaught TypeError: Cannot read property 'getGrammar' of undefined

At /Users/liry/.atom/packages/pretty-json/src/init.js:25

TypeError: Cannot read property 'getGrammar' of undefined
    at Object.doEntireFile (/packages/pretty-json/src/init.js:25:60)
    at HTMLElement.prettyJsonPrettify (/packages/pretty-json/src/init.js:111:24)
    at CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app/src/command-registry.js:384:49)
    at Object.didConfirmSelection (/Applications/Atom.app/Contents/Resources/app/node_modules/command-palette/lib/command-palette-view.js:152:35)
    at SelectListView.confirmSelection (/Applications/Atom.app/Contents/Resources/app/node_modules/atom-select-list/src/select-list-view.js:401:26)
    at HTMLDivElement.core:confirm (/Applications/Atom.app/Contents/Resources/app/node_modules/atom-select-list/src/select-list-view.js:106:20)
    at CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app/src/command-registry.js:384:49)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:621:22)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:412:28)
    at WindowEventHandler.handleDocumentKeyEvent (/Applications/Atom.app/Contents/Resources/app/src/window-event-handler.js:110:40)

Commands

     -5:20.3.0 datatip:toggle (input.hidden-input)
     -5:19.7.0 editor:select-line (input.hidden-input)
     -5:19.4.0 datatip:toggle (input.hidden-input)
     -4:05.7.0 command-palette:toggle (summary.welcome-summary.icon.icon-keyboard)
     -4:01.4.0 core:move-down (input.hidden-input)
     -2:43.8.0 core:confirm (input.hidden-input)
     -2:43.8.0 pretty-json:prettify (summary.welcome-summary.icon.icon-keyboard)

Non-Core Packages

atom-ide-ui 0.9.4 
pretty-json 2.0.0 
liry commented 6 years ago

FYI: Later, I tried Sort and Prettify and it worked without problem.

lexicalunit commented 6 years ago

I suppose we need a guard on the code editor.getGrammar() to handle the case when the editor reference is no longer valid (which can happen for many different reasons I think).

lexicalunit commented 6 years ago

Should be resolved in v2.0.1.