gandm / language-babel

ES2017, flow, React JSX and GraphQL grammar and transpilation for ATOM
https://atom.io/packages/language-babel
MIT License
476 stars 83 forks source link

Uncaught TypeError: Cannot read property 'code' of undefined #431

Closed robertrossmann closed 7 years ago

robertrossmann commented 7 years ago

Description

When I save a file with syntax errors and I have transpilation on save enabled, language-babel will throw an uncaught error.

The project uses the latest Babel beta version, 7.0.0-beta.3.

Expected behaviour

I think the correct behaviour would be to not throw any errors, or, at most, show a standard warning about syntax errors being present in the file. For the best developer experience, these warnings would not be shown in cases where ie. Linter is already active. If this is too difficult, then perhaps an option to supress such warnings could be added (Supress Transpile On Save Messages could be used to silence such warnings).

Steps to reproduce

  1. For language-babel, enable Transpile On Save and Create Transpiled Code
  2. Create a file with a syntax error, ie. with just the following contents:
    let
  3. Save the file

Atom: 1.22.0-beta1 x64 Electron: 1.6.15 OS: Mac OS X 10.13 Thrown From: language-babel package 2.75.2

Stack Trace

Uncaught TypeError: Cannot read property 'code' of undefined

At /Users/BeBe/.atom/packages/language-babel/lib/transpiler.coffee:207

TypeError: Cannot read property 'code' of undefined
    at /Users/BeBe/Dropbox/Repositories/language-babel/lib/transpiler.coffee:207:64
    at /Applications/Atom Beta.app/Contents/Resources/app/src/task.js:132:31
    at /Applications/Atom Beta.app/Contents/Resources/app/src/task.js:122:31
    at Function.module.exports.Emitter.simpleDispatch (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:25:20)
    at Emitter.module.exports.Emitter.emit (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:141:34)
    at ChildProcess.<anonymous> (/Applications/Atom Beta.app/Contents/Resources/app/src/task.js:74:40)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at process.nextTick (internal/child_process.js:752:12)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Commands

     -0:06.0 core:save (input.hidden-input)

Non-Core Packages

atom-chai-snippets 0.3.0 
atom-handlebars 1.3.0 
atom-ide-ui 0.5.1 
atom-material-ui 2.0.6 
atom-ternjs 0.18.3 
autocomplete-json 5.5.0 
autocomplete-modules 1.7.3 
build 0.69.0 
build-make 0.13.0 
build-npm-apm 0.12.0 
docblockr 0.11.0 
editorconfig 2.2.2 
file-icons 2.1.13 
git-plus 7.10.0 
git-projects 1.17.0 
git-time-machine 1.5.9 
go-debug 1.5.2 
go-plus 5.5.6 
go-signature-statusbar 1.2.3 
gruvbox-plus-syntax 1.3.1 
highlight-selected 0.13.1 
hyperclick 0.0.0 
ide-css 0.2.0 
ide-flowtype 0.17.4 
ide-go 0.4.0 
ide-typescript 0.6.2 
indent-guide-improved 1.4.13 
js-hyperclick 1.11.1 
language-babel 2.75.2 
language-diff 0.7.0 
language-docker 1.1.8 
language-dotenv 1.1.1 
language-gitignore 0.3.0 
language-graphql 0.9.0 
language-ini 1.19.0 
language-jade 0.7.2 
language-terraform 0.8.1 
linter-docker 0.2.1 
linter-eslint 8.3.2 
linter-golinter 1.2.2 
linter-govet 0.1.5 
linter-js-yaml 1.2.8 
linter-jsonlint 1.3.0 
linter-markdown 5.2.0 
linter-package-json-validator 2.0.0 
linter-shellcheck 1.4.6 
linter-terraform-syntax 1.2.1 
minimap 4.29.7 
minimap-cursorline 0.2.0 
minimap-git-diff 4.3.1 
minimap-linter 2.1.1 
platformio-ide-terminal 2.7.0 
pristine-ui 1.1.10 
sort-lines 0.18.0 
standardjs-snippets 2.6.2 
Stylus 3.1.1 
sync-settings 0.8.3 
tester 1.4.0 
tester-mocha 1.0.0 
todo-show 2.1.0 
gandm commented 7 years ago

I haven't tested Babel V7 yet. Looks like they changed the property name in the API that returns the error. I'll take a look.

gandm commented 7 years ago

Looks like a bug in Babel itself. babelTransformSync doesn't seem to work correctly and crashes out without returning an error object. image

robertrossmann commented 7 years ago

Hmm, looks like now the method is throwing an error instead of returning the error - what about wrapping the call in try/catch block...? That should help.

robertrossmann commented 7 years ago

I have tracked it down and sent a PR to Babel guys/gals: https://github.com/babel/babel/pull/6503

I think you can safely close this as it only occurs with the latest betas. Or you can keep it open to track the progres. Up to you. 😄

Thanks for looking into it!

gandm commented 7 years ago

Good to see your PR to fix this issue. Thanks.

iliutastoica commented 6 years ago

any updates ? still getting the error

iliutastoica commented 6 years ago

npm babel -v 6.0.1

gandm commented 6 years ago

@iliutastoica This issue was for Babel V7 and was reported to the Babel repo and should be fixed in the latest beta. The version you are given using npm is V6 and is fine. However npm will probably list the global installed babel and that won't likely be the version used in a real babel project. Normally, babel would exist in the node-modules folder of a babel project, or if a multi-repo such as Lerna was used at a higher level. This allows multiple version of babel to exist.

I would need more information if you believe this is a bug. Your project folder structure, .languagebabel, .babelrc, babel version in projects node-modules, etc. Please open another issue.

cnjimbo commented 4 years ago

[Enter steps to reproduce:]

  1. upgrade the babel to 7+
  2. save the file es6

Atom: 1.45.0 x64 Electron: 4.2.7 OS: Unknown Windows version Thrown From: language-babel package 2.85.0

Stack Trace

Uncaught TypeError: Cannot read property 'code' of undefined

At C:\Users\tangj15\.atom\packages\language-babel\lib\transpiler.coffee:215

TypeError: Cannot read property 'code' of undefined
    at /packages/language-babel/lib/transpiler.coffee:215:65
    at ~/AppData/Local/atom/app-1.45.0/resources/app/static/<embedded>:14:43875
    at ~/AppData/Local/atom/app-1.45.0/resources/app/static/<embedded>:14:43716
    at Function.simpleDispatch (~/AppData/Local/atom/app-1.45.0/resources/app/static/<embedded>:11:1214120)
    at Emitter.emit (~/AppData/Local/atom/app-1.45.0/resources/app/static/<embedded>:11:1215561)
    at ChildProcess.<anonymous> (~/AppData/Local/atom/app-1.45.0/resources/app/static/<embedded>:14:42817)
    at ChildProcess.emit (events.js:182:13)
    at emit (internal/child_process.js:812:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Commands

     -7:09.1.0 window:run-package-specs (input.hidden-input)
     -6:49 window:toggle-dev-tools (input.hidden-input)
     -6:41.6.0 sync-settings:backup (atom-workspace.workspace.scrollbars-visible-always.theme-one-dark-syntax.theme-atom-dark-ui)
  6x -6:22.8.0 core:save (input.hidden-input)
     -3:30.4.0 github:discard-changes-in-selected-files (span.github-FilePatchListView-path)
     -3:00.3.0 fuzzy-finder:toggle-file-finder (input.hidden-input)
 19x -2:52 core:backspace (input.hidden-input)
     -2:35.8.0 command-palette:toggle (input.hidden-input)
 14x -2:28.3.0 core:backspace (input.hidden-input)
     -2:18.7.0 settings-view:check-for-package-updates (input.hidden-input)
     -1:46.6.0 core:save (input.hidden-input)

Non-Core Packages

atom-beautify 0.33.4 
atom-ide-ui 0.13.0 
atom-ide-vue 1.3.1 
atom-live-server-plus 3.0.1 
atom-math 0.0.9 
atom-select-npm-install 1.0.2 
atom-ternjs 0.20.0 
atom-typescript 13.5.0 
autocomplete-modules 2.3.0 
autocomplete-paths 2.12.2 
console-log 1.10.0 
debug 0.0.1 
docblockr 0.13.7 
emmet 2.4.3 
file-icons 2.1.40 
git-control 0.9.0 
git-log 0.4.1 
git-plus 8.7.1 
hey-pane 1.2.0 
highlight-selected 0.17.0 
Hydrogen 2.14.1 
hyperclick 0.0.0 
ide-css 0.3.4 
ide-html 0.6.0 
ide-json 0.2.1 
ide-typescript 0.9.1 
ide-vue 0.1.9 
ide-yaml 0.7.0 
js-refactor 0.8.1 
js-refactor-atom 0.10.1 
language-babel 2.85.0 
language-diff 0.7.0 
language-postcss 1.3.1 
linter 2.3.1 
minimap 4.29.9 
minimap-highlight-selected 4.6.1 
npm-outdated 0.6.0 
npm-plus 0.4.0 
open-in-atom-pkg 1.0.1 
pigments 0.40.2 
prettier-atom 0.58.2 
pretty-json 2.1.2 
quick-log 0.3.1 
regex-railroad-diagram 0.19.4 
script 3.25.0 
scroll-sync 0.2.4 
scroll-through-time 0.3.1 
set-syntax 0.4.0 
sort-lines 0.19.0 
sync-settings 4.3.2 
tab-foldername-index 3.3.1 
toggle-quotes 1.1.4 
tree-view-copy-relative-path 1.2.0 
tree-view-git-status 1.5.3 
vue-fmt 0.1.1 
vue-template-beautify 0.1.2