 
     atom.packages.deactivatePackage(name) if atom.packages.isPackageActive(name)
 
+    errorMessage = "Uninstalling \u201C#{name}\u201D failed."
     onError = (error) =>
       @emitPackageEvent 'uninstall-failed', pack, error
       callback(error)

    else if options.packages
      args.push '--packages'

    apmProcess = @runCommand args, (code, stdout, stderr) ->
      if code is 0
        try
          packages = JSON.parse(stdout) ? []
          deferred.resolve(packages)
        catch parseError
          error = createJsonParseError("Searching for \u201C#{query}\u201D failed.", parseError, stdout)
          deferred.reject(error)
      else
        error = new Error("Searching for \u201C#{query}\u201D failed.")
        error.stdout = stdout
        error.stderr = stderr
        deferred.reject(error)

    apmProcess.onWillThrowError ({error, handle}) ->
        handle()
        deferred.reject(createProcessError("Searching for \u201C#{query}\u201D failed.", error))

    deferred.promise


        callback?()
        @emitPackageEvent 'uninstalled', pack
      else
        error = new Error(errorMessage)
        error.stdout = stdout
        error.stderr = stderr
        onError(error)

    handleProcessErrors(apmProcess, errorMessage, onError)

  canUpgrade: (installedPackage, availableVersion) ->
    return false unless installedPackage?
