<commit_before>// Copyright 2014, <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.md file.

// Package errs implements helpers functions to deal with errors.
package errs

import "runtime"
import "errors"

// Create a new error.
func New(str string) error {
	return errors.New(str)
}

// Panic if the error is not nil.
func Panic(err error) {
	if err != nil {
		panic(err)
	}
}

// Recovers from any panics and stores any errors to the given pointer. If the
// source of the panic was a Runtime error or not an error at all, then the
// panic continues.
func Recover(err *error) {
	switch ex := recover().(type) {
	case nil:
		// Do nothing
	case runtime.Error:
		panic(ex)
	case error:
		*err = ex
	default:
		panic(ex)
	}
}

// Recovers from any panics and ignores them.
// This is dangerous and should be used sparingly.
func NilRecover() {
	_ = recover()
}

// Convert errors from one type to another.
func Convert(err error, errNew error, errChks ...error) error {
	for _, errChk := range errChks {
		if err == errChk {
			return errNew
		}
	}
	return err
}

// Check if the provided error matches any of the others.
func Match(err error, errChks ...error) bool {
	return err != nil && Convert(err, nil, errChks...) == nil
}

// Ignore certain types of errors.<commit_msg>Add TODO about variadic version of Recover<commit_after>// Copyright 2014, <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.md file.

// Package errs implements helpers functions to deal with errors.
package errs

import "runtime"
import "errors"

// Create a new error.
func New(str string) error {
	return errors.New(str)
}

// Panic if the error is not nil.
func Panic(err error) {
	if err != nil {
		panic(err)
	}
}

// Recovers from any panics and stores any errors to the given pointer. If the
// source of the panic was a Runtime error or not an error at all, then the
// panic continues.
func Recover(err *error) {
	switch ex := recover().(type) {
	case nil:
		// Do nothing
	case runtime.Error:
		panic(ex)
	case error:
		*err = ex
	default:
		panic(ex)
	}
}

// TODO(jtsai): Remove the declaration of Recover above and replace it with the
// one below once Go's escape analysis improves. Otherwise, this function incurs
// some allocation penalty for every invocation.
//
// See: https://golang.org/issues/12006
/*
// Recovers from any panics and stores any errors to all of the input pointers.
// If the source of the panic was a Runtime error or not an error at all, then
// the panic continues.
func Recover(errs ...*error) {
	switch ex := recover().(type) {
	case nil:
		// Do nothing
	case runtime.Error:
		panic(ex)
	case error:
		for _, err := range errs {
			*err = ex
		}
	default:
		panic(ex)
	}
}
*/

// Recovers from any panics and ignores them.
// This is dangerous and should be used sparingly.
func NilRecover() {
	_ = recover()
}

// Convert errors from one type to another.
func Convert(err error, errNew error, errChks ...error) error {
	for _, errChk := range errChks {
		if err == errChk {
			return errNew
		}
	}
	return err
}

// Check if the provided error matches any of the others.
func Match(err error, errChks ...error) bool {
	return err != nil && Convert(err, nil, errChks...) == nil
}

// Ignore certain types of errors.
{'fraction_non_alphanumeric': 0.1060695344725987, 'fraction_numerical': 0.0038302887448438423, 'mean_word_length': 3.1002415458937196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '2519059', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1058, 'n_words': 469}