Re-throw stylesheet compile errors

This makes it consistent with other read errors. Previously a Notification
was returned in the error case causing errors downstream where the package's
stylesheets array was assumed to be a path/content tuple.

Closes atom/deprecation-cop#22
This commit is contained in:
Kevin Sawicki 2015-02-02 17:50:02 -08:00
parent a5ccfa6299
commit 853ad9cee3
5 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,4 @@
{
"name": "package-with-invalid-styles",
"version": "1.0.0"
}

View File

@ -0,0 +1 @@
{

View File

@ -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()

View File

@ -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

View File

@ -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()