<commit_before>import Service from '@ember/service';
import Space from 'hyperchannel/models/space';
import RemoteStorage from 'npm:remotestoragejs';
import Kosmos from 'npm:remotestorage-module-kosmos';
import config from 'hyperchannel/config/environment';

export default Service.extend({

  rs: null,

  init () {
    this._super(...arguments);

    const rs =  new RemoteStorage({modules: [Kosmos.default]});
    rs.access.claim('kosmos', 'rw');
    rs.caching.enable('/kosmos/');

    this.set('rs', rs);
  },

  addDefaultSpace() {
    let spaceConfig = config.spacePresets
                            .find(s => s.id === config.defaultSpaceId);

    let params = {
      id: spaceConfig.id,
      name: spaceConfig.name,
      protocol: spaceConfig.protocol,
      server: spaceConfig.server,
      channels: [
        '#hackerbeach',
        '#kosmos',
        '#kosmos-dev',
        '#kosmos-random',
        '#sockethub'
      ],
      botkaURL: spaceConfig.botkaURL
    };

    params.server.nickname = window.prompt("Choose a nickname");

    return this.rs.kosmos.spaces.store(params)
      .then(() => {
        console.debug('[remotestorage]', 'created/stored default space');

        let channels = params.channels;
        delete params.channels;

        const space = Space.create();
        space.setProperties(params);

        return { space, channels };
      });
  },

  saveSpace(space) {
    return this.rs.kosmos.spaces.store(space.serialize())
      .then(() => console.debug('[remotestorage]', `saved space ${space.get('name')} in RS`));
  },

  removeSpace(space) {
    return this.rs.kosmos.spaces.remove(space.get('id'))
      .then(() => console.debug('[remotestorage]', `removed space ${space.get('name')} from RS`));
  }

});<commit_msg>Log an error when saving space in RS fails<commit_after>import Service from '@ember/service';
import Space from 'hyperchannel/models/space';
import RemoteStorage from 'npm:remotestoragejs';
import Kosmos from 'npm:remotestorage-module-kosmos';
import config from 'hyperchannel/config/environment';

export default Service.extend({

  rs: null,

  init () {
    this._super(...arguments);

    const rs =  new RemoteStorage({modules: [Kosmos.default]});
    rs.access.claim('kosmos', 'rw');
    rs.caching.enable('/kosmos/');

    this.set('rs', rs);
  },

  addDefaultSpace() {
    let spaceConfig = config.spacePresets
                            .find(s => s.id === config.defaultSpaceId);

    let params = {
      id: spaceConfig.id,
      name: spaceConfig.name,
      protocol: spaceConfig.protocol,
      server: spaceConfig.server,
      channels: [
        '#hackerbeach',
        '#kosmos',
        '#kosmos-dev',
        '#kosmos-random',
        '#sockethub'
      ],
      botkaURL: spaceConfig.botkaURL
    };

    params.server.nickname = window.prompt("Choose a nickname");

    return this.rs.kosmos.spaces.store(params)
      .then(() => {
        console.debug('[remotestorage]', 'created/stored default space');

        let channels = params.channels;
        delete params.channels;

        const space = Space.create();
        space.setProperties(params);

        return { space, channels };
      });
  },

  saveSpace(space) {
    return this.rs.kosmos.spaces.store(space.serialize())
      .then(() => console.debug('[remotestorage]', `saved space ${space.get('name')}`))
      .catch(err => console.error('saving space failed:', err));
  },

  removeSpace(space) {
    return this.rs.kosmos.spaces.remove(space.get('id'))
      .then(() => console.debug('[remotestorage]', `removed space ${space.get('name')} from RS`));
  }

});
{'fraction_non_alphanumeric': 0.15808317267970257, 'fraction_numerical': 0.0, 'mean_word_length': 2.8762006403415157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '216909', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1122, 'n_words': 221}