<commit_before>package meep

import (
	"bytes"
	"fmt"
	"io"
	"reflect"
)

type meepAutodescriber interface {
	isMeepAutodescriber() *AutodescribingError
}

// note that this function applies if you have a type which embeds this one sans-*, but you have a ref to that type.
func (m *AutodescribingError) isMeepAutodescriber() *AutodescribingError { return m }

var customDescribe map[reflect.Type]func(reflect.Value, io.Writer) = map[reflect.Type]func(reflect.Value, io.Writer){
	reflect.TypeOf(Meep{}): nil,
	reflect.TypeOf(TraceableError{}): func(f reflect.Value, buf io.Writer) {
		buf = indenter(buf)
		buf.Write([]byte("Stack trace:\n"))
		buf = indenter(buf)
		//buf.(*rediscipliner).prefix = []byte{} // stacks already tab themselves in once
		m := reflect.Indirect(f).Interface().(TraceableError)
		m.WriteStack(buf)
	},
	reflect.TypeOf(CauseableError{}): func(f reflect.Value, buf io.Writer) {
		buf = indenter(buf)
		buf.Write([]byte("Caused by: "))
		m := reflect.Indirect(f).Interface().(CauseableError)
		if m.Cause == nil {
			buf.Write([]byte("<nil>\n"))
			return
		}
		// since we're now in multiline mode, we want to wrap up with a br.
		msg := []byte(m.Cause.Error())
		buf.Write(msg)
		if len(msg) == 0 || msg[len(msg)-1] != '\n' {
			buf.Write(br)
		}
	},
	reflect.TypeOf(GroupingError{}):       nil,
	reflect.TypeOf(AutodescribingError{}): nil,
}

func (m *AutodescribingError) ErrorMessage() string {
	// Check for initialization.
	// Can't do much of use if we didn't get initialized with a selfie reference.
	if m.self == nil {
		panic("meep:uninitialized")
	}
	// Unwind any pointer indirections.
	rv_self := reflect.ValueOf(m.self)
	for rv_self.Kind() == reflect.Ptr {
		rv_self = rv_self.Elem()
	}
	// Start buffering.
	buf := &bytes.Buffer{}
	// Annouce the type info.
	buf.WriteString("Error[")
	buf.WriteString(rv_self.Type().String())
	buf.WriteString("]: ") // FIXME only if fields<commit_msg>Let's not point out a nil cause.  There just... isn't a cause.<commit_after>package meep

import (
	"bytes"
	"fmt"
	"io"
	"reflect"
)

type meepAutodescriber interface {
	isMeepAutodescriber() *AutodescribingError
}

// note that this function applies if you have a type which embeds this one sans-*, but you have a ref to that type.
func (m *AutodescribingError) isMeepAutodescriber() *AutodescribingError { return m }

var customDescribe map[reflect.Type]func(reflect.Value, io.Writer) = map[reflect.Type]func(reflect.Value, io.Writer){
	reflect.TypeOf(Meep{}): nil,
	reflect.TypeOf(TraceableError{}): func(f reflect.Value, buf io.Writer) {
		buf = indenter(buf)
		buf.Write([]byte("Stack trace:\n"))
		buf = indenter(buf)
		//buf.(*rediscipliner).prefix = []byte{} // stacks already tab themselves in once
		m := reflect.Indirect(f).Interface().(TraceableError)
		m.WriteStack(buf)
	},
	reflect.TypeOf(CauseableError{}): func(f reflect.Value, buf io.Writer) {
		m := reflect.Indirect(f).Interface().(CauseableError)
		if m.Cause == nil {
			return
		}
		buf = indenter(buf)
		buf.Write([]byte("Caused by: "))
		// since we're now in multiline mode, we want to wrap up with a br.
		msg := []byte(m.Cause.Error())
		buf.Write(msg)
		if len(msg) == 0 || msg[len(msg)-1] != '\n' {
			buf.Write(br)
		}
	},
	reflect.TypeOf(GroupingError{}):       nil,
	reflect.TypeOf(AutodescribingError{}): nil,
}

func (m *AutodescribingError) ErrorMessage() string {
	// Check for initialization.
	// Can't do much of use if we didn't get initialized with a selfie reference.
	if m.self == nil {
		panic("meep:uninitialized")
	}
	// Unwind any pointer indirections.
	rv_self := reflect.ValueOf(m.self)
	for rv_self.Kind() == reflect.Ptr {
		rv_self = rv_self.Elem()
	}
	// Start buffering.
	buf := &bytes.Buffer{}
	// Annouce the type info.
	buf.WriteString("Error[")
	buf.WriteString(rv_self.Type().String())
	buf.WriteString("]: ") // FIXME only if fields
{'fraction_non_alphanumeric': 0.1569692267907939, 'fraction_numerical': 0.001034393586759762, 'mean_word_length': 4.116402116402116, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '7413227', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1352, 'n_words': 343}