diff --git a/spec/package-manager-spec.coffee b/spec/package-manager-spec.coffee index 4d6c56d4e..bab5bb260 100644 --- a/spec/package-manager-spec.coffee +++ b/spec/package-manager-spec.coffee @@ -18,7 +18,6 @@ describe "PackageManager", -> expect(pack.metadata.name).toBe "package-with-index" it "returns the package if it has an invalid keymap", -> - spyOn(console, 'warn') pack = atom.packages.loadPackage("package-with-broken-keymap") expect(pack instanceof Package).toBe true expect(pack.metadata.name).toBe "package-with-broken-keymap" @@ -30,10 +29,11 @@ describe "PackageManager", -> expect(pack.stylesheets.length).toBe 0 it "returns null if the package has an invalid package.json", -> - spyOn(console, 'warn') + addErrorHandler = jasmine.createSpy() + atom.notifications.onDidAddNotification(addErrorHandler) expect(atom.packages.loadPackage("package-with-broken-package-json")).toBeNull() - expect(console.warn.callCount).toBe(1) - expect(console.warn.argsForCall[0][0]).toContain("Failed to load package.json") + expect(addErrorHandler.callCount).toBe 1 + expect(addErrorHandler.argsForCall[0][0].message).toContain("Failed to load the package-with-broken-package-json package") it "returns null if the package is not found in any package directory", -> spyOn(console, 'warn') diff --git a/src/package-manager.coffee b/src/package-manager.coffee index bcd7dc28e..22c62e9b4 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -343,16 +343,22 @@ class PackageManager try metadata = Package.loadMetadata(packagePath) ? {} - if metadata.theme - pack = new ThemePackage(packagePath, metadata) - else - pack = new Package(packagePath, metadata) - pack.load() - @loadedPackages[pack.name] = pack - @emitter.emit 'did-load-package', pack - return pack catch error - console.warn "Failed to load package.json '#{path.basename(packagePath)}'", error.stack ? error + metadataPath = path.join(packagePath, 'package.json') + detail = error.message + " in #{metadataPath}" + stack = error.stack + "\n at #{metadataPath}:1:1" + message = "Failed to load the #{path.basename(packagePath)} package" + atom.notifications.addFatalError(message, {stack, detail, dismissable: true}) + return null + + if metadata.theme + pack = new ThemePackage(packagePath, metadata) + else + pack = new Package(packagePath, metadata) + pack.load() + @loadedPackages[pack.name] = pack + @emitter.emit 'did-load-package', pack + return pack else console.warn "Could not resolve '#{nameOrPath}' to a package path" null