<commit_before>package core

import (
	"fmt"
	"strings"

	"github.com/coel-lang/coel/src/lib/debug"
)

// ErrorType represents errors in the language and traces function calls for
// debugging.
type ErrorType struct {
	name, message string
	callTrace     []*debug.Info
}

// Eval evaluates a value into a WHNF.
func (e ErrorType) eval() Value {
	return e
}

// NewError creates an error value from its name and a formatted message.
func NewError(n, m string, xs ...interface{}) ErrorType {
	return ErrorType{
		name:    n,
		message: fmt.Sprintf(m, xs...),
	}
}

// Catch returns a dictionary containing a name and message of a catched error,
// or nil otherwise.
var Catch = NewLazyFunction(
	NewSignature([]string{"error"}, "", nil, ""),
	func(vs ...Value) Value {
		err, ok := EvalPure(vs[0]).(ErrorType)

		if !ok {
			return Nil
		}<commit_msg>Refactor error.go<commit_after>package core

import (
	"fmt"
	"strings"

	"github.com/coel-lang/coel/src/lib/debug"
)

// ErrorType represents errors in the language and traces function calls for
// debugging.
type ErrorType struct {
	name, message string
	callTrace     []*debug.Info
}

// Eval evaluates a value into a WHNF.
func (e ErrorType) eval() Value {
	return e
}

// NewError creates an error value from its name and a formatted message.
func NewError(n, m string, xs ...interface{}) ErrorType {
	return ErrorType{n, fmt.Sprintf(m, xs...), nil}
}

// Catch returns a dictionary containing a name and message of a catched error,
// or nil otherwise.
var Catch = NewLazyFunction(
	NewSignature([]string{"error"}, "", nil, ""),
	func(vs ...Value) Value {
		err, ok := EvalPure(vs[0]).(ErrorType)

		if !ok {
			return Nil
		}
{'fraction_non_alphanumeric': 0.1290898274836407, 'fraction_numerical': 0.001189767995240928, 'mean_word_length': 3.521505376344086, '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': '5862272', 'n_tokens_mistral': 571, 'n_tokens_neox': 541, 'n_words': 193}