Closed GHLeader closed 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
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)
-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)
atom-ide-ui 0.9.4
pretty-json 2.0.0
FYI: Later, I tried Sort and Prettify and it worked without problem.
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).
Should be resolved in v2.0.1.
[Enter steps to reproduce below:]
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
Commands
Config
Installed Packages