From ac11278bf48a0b027c67c0e1db87297ae9259af1 Mon Sep 17 00:00:00 2001 From: ebergeron Date: Sun, 7 Aug 2016 23:00:28 -0400 Subject: [PATCH] Added notification for both YAML and JSON .jsbeautifyrc parse error --- CHANGELOG.md | 1 + package.json | 6 +++++- src/beautifiers/index.coffee | 12 +++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e55516b56..5e7b4b3cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Closes [#776] (https://github.com/Glavin001/atom-beautify/issues/776) Add support for `collapse-preserve-inline` brace_style for javascript. - Closes [#786](https://github.com/Glavin001/atom-beautify/issues/786) YAPF configuration files are ignored. - Fix phpcbf hanging issue by closing stdin. See [#893](https://github.com/Glavin001/atom-beautify/issues/893) +- Add warning notification when parsing `.jsbeautifyrc` as JSON or YAML fails. See [#1106](https://github.com/Glavin001/atom-beautify/issues/1106) # v0.29.0 - Closes [#447](https://github.com/Glavin001/atom-beautify/issues/447). Improved Handlebars language support diff --git a/package.json b/package.json index 84e789aeb..279901c98 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,10 @@ { "name": "Arman Yessenamanov", "url": "https://github.com/yesenarman" + }, + { + "name": "Émile Bergeron", + "url": "https://github.com/emileber" } ], "engines": { @@ -270,4 +274,4 @@ "lint": "coffeelint src/ spec/", "code-docs": "codo && open docs/code/index.html" } -} \ No newline at end of file +} diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 0d29b66d7..e50d47deb 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -477,13 +477,23 @@ module.exports = class Beautifiers extends EventEmitter strip ?= require("strip-json-comments") externalOptions = JSON.parse(strip(contents)) catch e - + jsonError = e.message logger.debug "Failed parsing config as JSON: " + configPath # Attempt as YAML try yaml ?= require("yaml-front-matter") externalOptions = yaml.safeLoad(contents) catch e + title = "Atom Beautify failed to parse config as JSON or YAML" + detail = """ + Parsing '.jsbeautifyrc' at #{configPath} + JSON: #{jsonError} + YAML: #{e.message} + """ + atom?.notifications.addWarning(title, { + detail + dismissable : true + }) logger.debug "Failed parsing config as YAML and JSON: " + configPath externalOptions = {} else