<commit_before>var when = require('when');
var db;

var methods = {
  init: function (rawDB) {
    db = rawDB;
  },

  browse: function (options) {
    if (typeof options === 'number') {
      options = { where : { GroupId: options } };
    }

    return when.promise(function (resolve, reject) {
      db.Item.findAll(options).complete(function (err, items) {
        if (err) {
          return reject(err);
        }

        return resolve(items.map(function (item) {
          return item.values;
        }));
      });
    });
  },

  read: function (options) {
    var options = options || {};

    if (options.id) {
      options = +options.id;
    }

    return when.promise(function (resolve, reject) {
      db.Item.find(options).complete(function (err, item) {
        if (err) {
          return reject(err);
        }

        return resolve(item.values);
      });
    });<commit_msg>Provide an error when trying to get a non-existent model from the db<commit_after>var when = require('when');
var db;

var methods = {
  init: function (rawDB) {
    db = rawDB;
  },

  browse: function (options) {
    if (typeof options === 'number') {
      options = { where : { GroupId: options } };
    }

    return when.promise(function (resolve, reject) {
      db.Item.findAll(options).complete(function (err, items) {
        if (err) {
          return reject(err);
        }

        return resolve(items.map(function (item) {
          return item.values;
        }));
      });
    });
  },

  read: function (options) {
    var options = options || {};

    if (options.id) {
      options = +options.id;
    }

    return when.promise(function (resolve, reject) {
      db.Item.find(options).complete(function (err, item) {
        if (err) {
          return reject(err);
        }

        if (!item) {
          return reject(new Error('could not find a non-existent item with options: ' + JSON.stringify(options)));
        }

        return resolve(item.values);
      });
    });
{'fraction_non_alphanumeric': 0.1455, 'fraction_numerical': 0.0, 'mean_word_length': 2.107142857142857, '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': '6516535', 'n_tokens_mistral': 614, 'n_tokens_neox': 598, 'n_words': 149}