<commit_before>var angular = require('angular')
var formsConfig = require('../../../config/formsConfig')

require('../app').directive('configLabel', /* @ngInject */function () {
  return {
    restrict: 'E',
    template: '{{$ctrl.label}}',
    scope: {
      config: '@?',
      value: '@?'
    },
    controller: /* @ngInject */function ($scope, $attrs, $translate) {
      var $ctrl = this
      $ctrl.label = $attrs.value

      if (!($attrs.config in formsConfig)) {
        throw new Error('Unsupported config type: "' + $attrs.config + '"\nAvailable values are: ' + Object.keys(formsConfig).join(', '))
      }

      $translate(formsConfig[$attrs.config][$scope.value].label).then(function (val) { $ctrl.label = val }).catch(angular.noop)
      $ctrl.label = $translate.instant(formsConfig[$attrs.config][$scope.value].label)
    },
    controllerAs: '$ctrl'
  }
})
<commit_msg>Handle empty value for configLabel and invalid config<commit_after>var angular = require('angular')
var formsConfig = require('../../../config/formsConfig')

require('../app').directive('configLabel', /* @ngInject */function () {
  return {
    restrict: 'E',
    template: '{{$ctrl.label}}',
    scope: {
      config: '@?',
      value: '@?'
    },
    controller: /* @ngInject */function ($scope, $attrs, $translate) {
      var $ctrl = this
      $ctrl.label = $attrs.value

      if (!($attrs.config in formsConfig)) {
        throw new Error('Unsupported config type: "' + $attrs.config + '"\nAvailable values are: ' + Object.keys(formsConfig).join(', '))
      }

      // if not selected, display nothing
      if (!$scope.value) {
        $ctrl.label = ''
        return
      }

      var currentValue = formsConfig[$attrs.config][$scope.value]

      // validate config has label
      if (!('label' in currentValue)) {
        throw new Error('formsConfig[' + $attrs.config + '][' + $scope.value + '] is missing label key')
      }

      $translate(currentValue.label).then(function (val) { $ctrl.label = val }).catch(angular.noop)
      $ctrl.label = $translate.instant(formsConfig[$attrs.config][$scope.value].label)
    },
    controllerAs: '$ctrl'
  }
})

{'fraction_non_alphanumeric': 0.1876737720111214, 'fraction_numerical': 0.0, 'mean_word_length': 2.9614678899082567, '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': '3211482', 'n_tokens_mistral': 651, 'n_tokens_neox': 648, 'n_words': 138}