示例#1
0
文件: errors.go 项目: robxu9/kahinah
func (p *PanicHandler) Err500(ex interface{}, ctx context.Context, rw http.ResponseWriter, r *http.Request) {
	renderer := render.FromContext(ctx)

	data := make(map[string]interface{})
	data["Title"] = "eek fire FIRE"
	data["Nav"] = -1
	data["environment"] = runMode
	data["authenticated"] = cas.Username(r)
	data["copyright"] = time.Now().Year()
	data["error"] = fmt.Sprintf("%v", ex)

	stackTrace := errors.Wrap(ex, 4).ErrorStack()

	klog.Critical("err  (%v): Internal Server Error: %v", r.RemoteAddr, ex)
	klog.Critical("err  (%v): Stacktrace: %v", r.RemoteAddr, stackTrace)

	if mode := conf.GetDefault("runMode", "dev").(string); mode == "dev" {
		// dump the stacktrace out on the page too
		data["stacktrace"] = stackTrace
	}

	renderer.HTML(rw, 500, "errors/500", data)
}
示例#2
0
文件: abf.go 项目: robxu9/kahinah
// makeDiff shells out to the cmd line git to get a patch. Unfortunately, this
// may need tweaking given the modifications that OpenMandriva have done to
// their ABF.
func (a *ABF) makeDiff(gitURL, fromHash, toHash string) string {
	// make sure it's not disabled
	if !abfGitDiff {
		return "Diff creation disabled."
	}

	// ugh, looks like we'll have to do this the sadly hard way
	tmpdir, err := ioutil.TempDir("", "kahinah_")
	if err != nil {
		return "Error creating directory for diff creation: " + err.Error()
	}

	defer os.RemoveAll(tmpdir)

	if strings.Contains(gitURL, "@") {
		gitURL = gitURL[:strings.Index(gitURL, "//")+2] + gitURL[strings.Index(gitURL, "@")+1:]
	}

	urlToUse := gitURL
	if abfGitDiffSSH {
		urlToUse = strings.Replace("git@"+gitURL[strings.Index(gitURL, "//")+2:], "/", ":", 1)
	}

	// reusable bytes output
	var b bytes.Buffer

	gitclonecmd := exec.Command("git", "clone", urlToUse, tmpdir)
	gitclonecmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0") // git 2.3+
	gitclonecmd.Stderr = &b
	gitclonecmd.Stdout = &b
	gitclonecmd.Start()

	gitresult := make(chan error, 1)
	go func() {
		gitresult <- gitclonecmd.Wait()
	}()
	select {
	case <-time.After(10 * time.Minute):
		if err := gitclonecmd.Process.Kill(); err != nil {
			klog.Criticalf("abf: calling git to kill failed: %v", err)
		}
		<-gitresult // allow goroutine to exit
		klog.Critical("abf: git process called to kill")
	case err := <-gitresult:
		if err != nil { // git exited with non-zero status
			klog.Criticalf("abf: calling git failed: %v", err)
			return "Repository could not be cloned for diff: " + err.Error()
		}
	}

	if fromHash == "" || fromHash == toHash {
		gitdiffcmd := exec.Command("git", "show", "--format=fuller", "--patch-with-stat", "--summary", toHash)
		gitdiffcmd.Dir = tmpdir

		gitdiff, err := gitdiffcmd.CombinedOutput()
		if err != nil {
			klog.Criticalf("abf: calling git diff failed: %v", err)
			return "No diff available: " + err.Error()
		}

		return fmt.Sprintf("$ git show --format=fuller --patch-with-stat --summary %s\n\n%s", toHash, string(gitdiff))
	}

	gitdiffcmd := exec.Command("git", "diff", "--patch-with-stat", "--summary", fromHash+".."+toHash)
	gitdiffcmd.Dir = tmpdir

	gitdiff, err := gitdiffcmd.CombinedOutput()
	if err != nil {
		fmt.Printf("%s", gitdiff)
		return "No diff available: " + err.Error()
	}

	return fmt.Sprintf("$ git diff --patch-with-stat --summary %s\n\n%s", fromHash+".."+toHash, string(gitdiff))
}