             throw new Error("ADPU sending failed " + ex)
     catch ex
       e ex
+
+  _handleLoadingScriptError: (ex) ->
+    switch ex.message
+      when 'timeout'
+        @_waitForPowerCycle()
+      else @_failure(Errors.CommunicationError)
+    return
 
   _findOriginalKey: ->
     if @_lastOriginalKey?

    .then =>
      @_success()
      @_isOsLoaded = no
    .fail =>
      @_failure(Errors.FailedToInitOs)

  _processReloadBootloaderFromOs: ->
    @_removeUserApproval('erasure')

      .then =>
        @_waitForPowerCycle(null, yes)
      .fail (e) =>
        unless @_handleLoadingScriptError(e)
          switch @_getCard().SW
            when 0x6985
              l "Failed procces RELOAD BL FROM OS"
              @_processInitOs()
              return
            when 0x6faa then @_failure(Errors.ErrorDueToCardPersonalization)
            else @_failure(Errors.CommunicationError)
          @_waitForDisconnectDongle()
    .fail (err) ->
      console.error(err)

