<commit_before>/**
 * VclController
 *
 * @description :: Server-side logic for managing vcls
 * @help        :: See http://links.sailsjs.org/docs/controllers
 */
var child_process = require('child_process');
var fs = require('fs');
var path = require('path');
var temp = require('temp');
var url = require('url');

module.exports = {
	index: function (req, res) {
    const defaultVcl = 'vcl 4.0; backend default { .host = "www.vclfiddle.net"; .port = "80"; }';
    return res.view({
      vcl: defaultVcl,
      har: '',
      log: ''
    });
  },

  run: function (req, res) {
    var vcl = req.body.vcl;
    var har = req.body.har;

    try {
      var parsedHar = JSON.parse(har);
      har = JSON.stringify(parsedHar, null, '  ');
    } catch (ex) {

      return res.view('vcl/index', {
        vcl: vcl,
        har: har,
        log: 'Failed to parse HAR. ' + ex
      });

    }

    ContainerService.replayHarWithVcl(parsedHar, vcl, function (err, output) {

      var log = output.varnishlog;
      if (err) {
        log = 'Error: ' + err;
      } else if (output.runlog.length > 0) {
        log = 'Error: ' + output.runlog;
      } else {
        log = output.varnishlog; // TODO parse and format
      }

      return res.ok({
        vcl: vcl,
        har: har,
        log: log
      }, 'vcl/index');

    });

  }

};
<commit_msg>Remove assumption that output will always be populated.<commit_after>/**
 * VclController
 *
 * @description :: Server-side logic for managing vcls
 * @help        :: See http://links.sailsjs.org/docs/controllers
 */
var child_process = require('child_process');
var fs = require('fs');
var path = require('path');
var temp = require('temp');
var url = require('url');

module.exports = {
	index: function (req, res) {
    const defaultVcl = 'vcl 4.0; backend default { .host = "www.vclfiddle.net"; .port = "80"; }';
    return res.view({
      vcl: defaultVcl,
      har: '',
      log: ''
    });
  },

  run: function (req, res) {
    var vcl = req.body.vcl;
    var har = req.body.har;

    try {
      var parsedHar = JSON.parse(har);
      har = JSON.stringify(parsedHar, null, '  ');
    } catch (ex) {

      return res.view('vcl/index', {
        vcl: vcl,
        har: har,
        log: 'Failed to parse HAR. ' + ex
      });

    }

    ContainerService.replayHarWithVcl(parsedHar, vcl, function (err, output) {

      var log = '';
      if (err) {
        log = 'Error: ' + err;
      } else if (output.runlog.length > 0) {
        log = 'Error: ' + output.runlog;
      } else {
        log = output.varnishlog; // TODO parse and format
      }

      return res.ok({
        vcl: vcl,
        har: har,
        log: log
      }, 'vcl/index');

    });

  }

};

{'fraction_non_alphanumeric': 0.15926605504587155, 'fraction_numerical': 0.003669724770642202, 'mean_word_length': 2.0977272727272727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2999260', 'n_tokens_mistral': 949, 'n_tokens_neox': 918, 'n_words': 234}