diff --git a/spec/fixtures/packages/package-with-invalid-styles/package.json b/spec/fixtures/packages/package-with-invalid-styles/package.json new file mode 100644 index 000000000..9d2aa7fe3 --- /dev/null +++ b/spec/fixtures/packages/package-with-invalid-styles/package.json @@ -0,0 +1,4 @@ +{ + "name": "package-with-invalid-styles", + "version": "1.0.0" +} diff --git a/spec/fixtures/packages/package-with-invalid-styles/styles/index.less b/spec/fixtures/packages/package-with-invalid-styles/styles/index.less new file mode 100644 index 000000000..98232c64f --- /dev/null +++ b/spec/fixtures/packages/package-with-invalid-styles/styles/index.less @@ -0,0 +1 @@ +{ diff --git a/spec/package-manager-spec.coffee b/spec/package-manager-spec.coffee index c3aaefa15..3d79b4631 100644 --- a/spec/package-manager-spec.coffee +++ b/spec/package-manager-spec.coffee @@ -23,6 +23,12 @@ describe "PackageManager", -> expect(pack instanceof Package).toBe true expect(pack.metadata.name).toBe "package-with-broken-keymap" + it "returns the package if it has an invalid stylesheet", -> + pack = atom.packages.loadPackage("package-with-invalid-styles") + expect(pack instanceof Package).toBe true + expect(pack.metadata.name).toBe "package-with-invalid-styles" + expect(pack.stylesheets.length).toBe 0 + it "returns null if the package has an invalid package.json", -> spyOn(console, 'warn') expect(atom.packages.loadPackage("package-with-broken-package-json")).toBeNull() diff --git a/spec/theme-manager-spec.coffee b/spec/theme-manager-spec.coffee index ffbabc7cf..94e5fad61 100644 --- a/spec/theme-manager-spec.coffee +++ b/spec/theme-manager-spec.coffee @@ -364,12 +364,13 @@ describe "ThemeManager", -> throw new Error('EACCES permission denied "styles.less"') atom.notifications.onDidAddNotification addErrorHandler = jasmine.createSpy() - it "creates an error notification", -> + it "creates an error notification and does not add the stylesheet", -> themeManager.loadUserStylesheet() expect(addErrorHandler).toHaveBeenCalled() note = addErrorHandler.mostRecentCall.args[0] expect(note.getType()).toBe 'error' expect(note.getMessage()).toContain 'Error loading' + expect(atom.styles.styleElementsBySourcePath[atom.styles.getUserStyleSheetPath()]).toBeUndefined() describe "when there is an error watching the user stylesheet", -> addErrorHandler = null diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 24a86f05a..9cf3537a1 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -266,7 +266,11 @@ class ThemeManager """ atom.notifications.addError(message, dismissable: true) - userStylesheetContents = @loadStylesheet(userStylesheetPath, true) + try + userStylesheetContents = @loadStylesheet(userStylesheetPath, true) + catch + return + @userStyleSheetDisposable = atom.styles.addStyleSheet(userStylesheetContents, sourcePath: userStylesheetPath, priority: 2) loadBaseStylesheets: -> @@ -320,6 +324,7 @@ class ThemeManager detail = error.message atom.notifications.addError(message, {detail, dismissable: true}) + throw error removeStylesheet: (stylesheetPath) -> @styleSheetDisposablesBySourcePath[stylesheetPath]?.dispose()