Merge pull request #956 from atom/mc-bad-package

Make package loading more robust
This commit is contained in:
Matt Colyer 2013-10-11 12:55:53 -07:00
commit 0255faded1
6 changed files with 32 additions and 18 deletions

View File

@ -19,6 +19,14 @@ describe "the `atom` global", ->
expect(object.data).toBe 5
expect(pack.activateStylesheets).toHaveBeenCalled()
it "continues if the package has an invalid package.json", ->
config.set("core.disabledPackages", [])
expect(-> atom.loadPackage("package-with-broken-package-json")).not.toThrow()
it "continues if the package has an invalid keymap", ->
config.set("core.disabledPackages", [])
expect(-> atom.loadPackage("package-with-broken-keymap")).not.toThrow()
describe ".unloadPackage(name)", ->
describe "when the package is active", ->
it "throws an error", ->

View File

@ -0,0 +1 @@
INVALID

View File

@ -0,0 +1 @@
INVALID

View File

@ -63,7 +63,8 @@ beforeEach ->
config.set "editor.fontFamily", "Courier"
config.set "editor.fontSize", 16
config.set "editor.autoIndent", false
config.set "core.disabledPackages", ["package-that-throws-an-exception"]
config.set "core.disabledPackages", ["package-that-throws-an-exception",
"package-with-broken-package-json", "package-with-broken-keymap"]
config.save.reset()
atom.config = config
window.config = config

View File

@ -28,26 +28,28 @@ class AtomPackage extends Package
getType: -> 'atom'
load: ->
@metadata = {}
@stylesheets = []
@keymaps = []
@menus = []
@grammars = []
@scopedProperties = []
@measure 'loadTime', =>
try
@metadata = Package.loadMetadata(@path)
if @isTheme()
@stylesheets = []
@keymaps = []
@menus = []
@grammars = []
@scopedProperties = []
else
@loadKeymaps()
@loadMenus()
@loadStylesheets()
@loadGrammars()
@loadScopedProperties()
return if @isTheme()
if @metadata.activationEvents?
@registerDeferredDeserializers()
else
@requireMainModule()
@loadKeymaps()
@loadMenus()
@loadStylesheets()
@loadGrammars()
@loadScopedProperties()
if @metadata.activationEvents?
@registerDeferredDeserializers()
else
@requireMainModule()
catch e
console.warn "Failed to load package named '#{@name}'", e.stack ? e

View File

@ -66,8 +66,9 @@ class PackageManager
if packagePath = @resolvePackagePath(name)
return pack if pack = @getLoadedPackage(name)
pack = Package.load(packagePath, options)
if pack.metadata.theme
if pack.metadata?.theme
atom.themes.register(pack)
else
@loadedPackages[pack.name] = pack