<commit_before>package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"time"

	"github.com/spacemonkeygo/errors"
	"github.com/spacemonkeygo/errors/try"
	"polydawn.net/repeatr/cli"
)

func main() {
	try.Do(func() {
		cli.Main(os.Args, os.Stderr)
	}).Catch(cli.Error, func(err *errors.Error) {
		// Errors marked as valid user-facing issues get a nice
		// pretty-printed route out, and may include specified exit codes.
		if isDebugMode() {
			// in debug-mode, repanic all the way to death so that we get all of golang's built in log features.
			panic(err)
		} else {
			// print nicely.
			fmt.Fprintf(os.Stderr,
				"Repeatr was unable to complete your request!\n"+
					"%s\n",
				err)
			// exit, taking the specified code if any.
			code := errors.GetData(err, cli.ExitCodeKey)
			if code == nil {
				os.Exit(int(cli.EXIT_USER))
			}
			os.Exit(int(code.(cli.ExitCode)))
		}
	}).CatchAll(func(err error) {
		// Errors that aren't marked as valid user-facing issues should be
		// logged in preparation for a bug report.
		if isDebugMode() {
			// in debug-mode, repanic all the way to death so that we get all of golang's built in log features.
			panic(err)
		} else {
			// save the error to a file.  we want to keep the stacks, but not scare away the user.
			logPath, saveErr := saveErrorReport(err)
			var saveMsg string
			if saveErr == nil {
				saveMsg = fmt.Sprintf("We've logged the full error to a file: %q.  Please include this in the report.", logPath)
			} else {
				saveMsg = fmt.Sprintf("Additionally, we were unable to save a full log of the problem (\"%s\").", saveErr)
			}
			fmt.Fprintf(os.Stderr,
				"Repeatr encountered a serious issue and was unable to complete your request!\n"+
					"Please file an issue to help us fix it.\n"+
					"%s\n"+
					"\n"+
					"This is the short version of the problem:\n"+
					"%s\n",
				saveMsg,
				errors.GetMessage(err),
			)
			os.Exit(int(cli.EXIT_UNKNOWNPANIC))
		}
	})
}

func isDebugMode() bool {
	// if either "DEBUG" or "REPEATR_DEBUG" env vars are set, we're in debug mode.
	return len(os.Getenv("DEBUG")) != 0 || len(os.Getenv("REPEATR_DEBUG")) != 0
}

func saveErrorReport(caught error) (string, error) {
	logFile, err := ioutil.TempFile(os.TempDir(), "repeatr-error-report-")
	if err != nil {
		return "", err
	}
	defer logFile.Close()
	fmt.Fprintf(logFile, "Repeatr error report\n")
	fmt.Fprintf(logFile, "====================\n")
	fmt.Fprintf(logFile, "Date: %s\n", time.Now())
	fmt.Fprintf(logFile, "Briefly: %s\n", errors.GetMessage(caught))
	fmt.Fprintf(logFile, "\n")
	fmt.Fprintf(logFile, "Full error:\n")
	fmt.Fprintf(logFile, "-----------\n")
	fmt.Fprintf(logFile, "%s\n", caught)
	fmt.Fprintf(logFile, "\n")
	fmt.Fprintf(logFile, "Structure:\n")
	fmt.Fprintf(logFile, "-----------\n")
	fmt.Fprintf(logFile, "%#v\n", caught)
	fmt.Fprintf(logFile, "\n")
	// TODO full stack viewed from here.  yank the formatting stuff from spacemonkey errors
	return logFile.Name(), nil
}
<commit_msg>Hotfix, actually run the main method.<commit_after>package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"time"

	"github.com/spacemonkeygo/errors"
	"github.com/spacemonkeygo/errors/try"
	"polydawn.net/repeatr/cli"
)

func main() {
	try.Do(func() {
		cli.Main(os.Args, os.Stderr)
	}).Catch(cli.Error, func(err *errors.Error) {
		// Errors marked as valid user-facing issues get a nice
		// pretty-printed route out, and may include specified exit codes.
		if isDebugMode() {
			// in debug-mode, repanic all the way to death so that we get all of golang's built in log features.
			panic(err)
		} else {
			// print nicely.
			fmt.Fprintf(os.Stderr,
				"Repeatr was unable to complete your request!\n"+
					"%s\n",
				err)
			// exit, taking the specified code if any.
			code := errors.GetData(err, cli.ExitCodeKey)
			if code == nil {
				os.Exit(int(cli.EXIT_USER))
			}
			os.Exit(int(code.(cli.ExitCode)))
		}
	}).CatchAll(func(err error) {
		// Errors that aren't marked as valid user-facing issues should be
		// logged in preparation for a bug report.
		if isDebugMode() {
			// in debug-mode, repanic all the way to death so that we get all of golang's built in log features.
			panic(err)
		} else {
			// save the error to a file.  we want to keep the stacks, but not scare away the user.
			logPath, saveErr := saveErrorReport(err)
			var saveMsg string
			if saveErr == nil {
				saveMsg = fmt.Sprintf("We've logged the full error to a file: %q.  Please include this in the report.", logPath)
			} else {
				saveMsg = fmt.Sprintf("Additionally, we were unable to save a full log of the problem (\"%s\").", saveErr)
			}
			fmt.Fprintf(os.Stderr,
				"Repeatr encountered a serious issue and was unable to complete your request!\n"+
					"Please file an issue to help us fix it.\n"+
					"%s\n"+
					"\n"+
					"This is the short version of the problem:\n"+
					"%s\n",
				saveMsg,
				errors.GetMessage(err),
			)
			os.Exit(int(cli.EXIT_UNKNOWNPANIC))
		}
	}).Done()
}

func isDebugMode() bool {
	// if either "DEBUG" or "REPEATR_DEBUG" env vars are set, we're in debug mode.
	return len(os.Getenv("DEBUG")) != 0 || len(os.Getenv("REPEATR_DEBUG")) != 0
}

func saveErrorReport(caught error) (string, error) {
	logFile, err := ioutil.TempFile(os.TempDir(), "repeatr-error-report-")
	if err != nil {
		return "", err
	}
	defer logFile.Close()
	fmt.Fprintf(logFile, "Repeatr error report\n")
	fmt.Fprintf(logFile, "====================\n")
	fmt.Fprintf(logFile, "Date: %s\n", time.Now())
	fmt.Fprintf(logFile, "Briefly: %s\n", errors.GetMessage(caught))
	fmt.Fprintf(logFile, "\n")
	fmt.Fprintf(logFile, "Full error:\n")
	fmt.Fprintf(logFile, "-----------\n")
	fmt.Fprintf(logFile, "%s\n", caught)
	fmt.Fprintf(logFile, "\n")
	fmt.Fprintf(logFile, "Structure:\n")
	fmt.Fprintf(logFile, "-----------\n")
	fmt.Fprintf(logFile, "%#v\n", caught)
	fmt.Fprintf(logFile, "\n")
	// TODO full stack viewed from here.  yank the formatting stuff from spacemonkey errors
	return logFile.Name(), nil
}

{'fraction_non_alphanumeric': 0.15782426778242678, 'fraction_numerical': 0.0006694560669456067, 'mean_word_length': 3.274678111587983, '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': '5025940', 'n_tokens_mistral': 2360, 'n_tokens_neox': 2133, 'n_words': 630}