<commit_before>(function(window) {

  var hasLocalStorage;
  var LS_STATE_KEY = "remotestorage:widget:state";
  // states allowed to immediately jump into after a reload.
  var VALID_ENTRY_STATES = {
    initial: true,
    connected: true,
    offline: true
  };

  function stateSetter(widget, state) {
    RemoteStorage.log('[Widget] Producing stateSetter for', state);
    return function() {
      RemoteStorage.log('[Widget] Setting state', state, arguments);
      if (hasLocalStorage) {
        localStorage[LS_STATE_KEY] = state;
      }
      if (widget.view) {
        if (widget.rs.remote) {
          widget.view.setUserAddress(widget.rs.remote.userAddress);
        }
        widget.view.setState(state, arguments);
      } else {
        widget._rememberedState = state;
      }
    };
  }

  function errorsHandler(widget) {
    return function(error) {
      if (widget.view) {
        if (error instanceof RemoteStorage.DiscoveryError) {
          console.error('Discovery failed', error, '"' + error.message + '"');
          widget.view.setState('initial', [error.message]);
        } else if (error instanceof RemoteStorage.SyncError) {
          widget.view.setState('offline', []);
        } else if (error instanceof RemoteStorage.Unauthorized) {
          widget.view.setState('unauthorized');
        } else {
          RemoteStorage.log('[Widget] Unknown error');
          widget.view.setState('error', [error]);
        }
      } else if(remoteStorage) {
        remoteStorage._emit('error', error);
      } else {
        RemoteStorage.log('[widget] Undisplayed error:', error);
      }
    };
  }

  function flashFor(evt) {
    if (evt.method === 'GET' && evt.isFolder) {
      return false;
    }
    return true;
  }
<commit_msg>remove duplicate emission of error event<commit_after>(function(window) {

  var hasLocalStorage;
  var LS_STATE_KEY = "remotestorage:widget:state";
  // states allowed to immediately jump into after a reload.
  var VALID_ENTRY_STATES = {
    initial: true,
    connected: true,
    offline: true
  };

  function stateSetter(widget, state) {
    RemoteStorage.log('[Widget] Producing stateSetter for', state);
    return function() {
      RemoteStorage.log('[Widget] Setting state', state, arguments);
      if (hasLocalStorage) {
        localStorage[LS_STATE_KEY] = state;
      }
      if (widget.view) {
        if (widget.rs.remote) {
          widget.view.setUserAddress(widget.rs.remote.userAddress);
        }
        widget.view.setState(state, arguments);
      } else {
        widget._rememberedState = state;
      }
    };
  }

  function errorsHandler(widget) {
    return function(error) {
      if (widget.view) {
        if (error instanceof RemoteStorage.DiscoveryError) {
          console.error('Discovery failed', error, '"' + error.message + '"');
          widget.view.setState('initial', [error.message]);
        } else if (error instanceof RemoteStorage.SyncError) {
          widget.view.setState('offline', []);
        } else if (error instanceof RemoteStorage.Unauthorized) {
          widget.view.setState('unauthorized');
        } else {
          RemoteStorage.log('[Widget] Unknown error');
          widget.view.setState('error', [error]);
        }
      } else {
        RemoteStorage.log('[widget] Undisplayed error:', error);
      }
    };
  }

  function flashFor(evt) {
    if (evt.method === 'GET' && evt.isFolder) {
      return false;
    }
    return true;
  }

{'fraction_non_alphanumeric': 0.12870716959401093, 'fraction_numerical': 0.0, 'mean_word_length': 2.585139318885449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5657918', 'n_tokens_mistral': 1011, 'n_tokens_neox': 1006, 'n_words': 211}