<commit_before>#include "./compile.h"
#include "tree_sitter/compiler.h"

namespace node_tree_sitter_compiler {

using namespace v8;

NAN_METHOD(Compile) {
  String::Utf8Value grammar_json(info[0]);
  TSCompileResult compile_result = ts_compile_grammar(*grammar_json);

  if (compile_result.error_message) {
    Local<Value> error = Nan::Error(compile_result.error_message);
    Local<Object>::Cast(error)->Set(Nan::New("isGrammarError").ToLocalChecked(), Nan::True());
    Nan::ThrowError(error);
  } else {
    info.GetReturnValue().Set(Nan::New(compile_result.code).ToLocalChecked());
  }
}

}  // namespace node_tree_sitter_compiler
<commit_msg>Use the error_type field to check for errors<commit_after>#include "./compile.h"
#include "tree_sitter/compiler.h"

namespace node_tree_sitter_compiler {

using namespace v8;

NAN_METHOD(Compile) {
  String::Utf8Value grammar_json(info[0]);
  TSCompileResult compile_result = ts_compile_grammar(*grammar_json);

  if (compile_result.error_type != TSCompileErrorTypeNone) {
    Local<Value> error = Nan::Error(compile_result.error_message);
    Local<Object>::Cast(error)->Set(Nan::New("isGrammarError").ToLocalChecked(), Nan::True());
    Nan::ThrowError(error);
  } else {
    info.GetReturnValue().Set(Nan::New(compile_result.code).ToLocalChecked());
  }
}

}  // namespace node_tree_sitter_compiler

{'fraction_non_alphanumeric': 0.1437037037037037, 'fraction_numerical': 0.0044444444444444444, 'mean_word_length': 6.5055555555555555, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5150710', 'n_tokens_mistral': 468, 'n_tokens_neox': 445, 'n_words': 62}