packer/panic.go
Anurag Sharma 543123ac17
Some checks are pending
build / get-go-version (push) Waiting to run
build / set-product-version (push) Waiting to run
build / generate-metadata-file (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} freebsd 386 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} netbsd 386 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} openbsd 386 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} solaris 386 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} windows 386 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} freebsd amd64 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} netbsd amd64 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} openbsd amd64 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} solaris amd64 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} windows amd64 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} freebsd arm build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} netbsd arm build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} openbsd arm build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} linux 386 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} linux amd64 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} linux arm build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} linux arm64 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} linux ppc64le build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} darwin amd64 build (push) Blocked by required conditions
build / Go ${{ needs.get-go-version.outputs.go-version }} darwin arm64 build (push) Blocked by required conditions
build / Docker light 386 build (push) Blocked by required conditions
build / Docker light amd64 build (push) Blocked by required conditions
build / Docker light arm build (push) Blocked by required conditions
build / Docker light arm64 build (push) Blocked by required conditions
build / Docker full 386 build (push) Blocked by required conditions
build / Docker full amd64 build (push) Blocked by required conditions
build / Docker full arm build (push) Blocked by required conditions
build / Docker full arm64 build (push) Blocked by required conditions
Go Test / get-go-version (push) Waiting to run
Go Test / Linux go tests (push) Blocked by required conditions
Go Test / Darwin go tests (push) Blocked by required conditions
Go Test / Windows go tests (push) Blocked by required conditions
Go Validate / get-go-version (push) Waiting to run
Go Validate / Go Mod Tidy (push) Blocked by required conditions
Go Validate / Lint (push) Blocked by required conditions
Go Validate / Fmt check (push) Blocked by required conditions
Go Validate / Generate check (push) Blocked by required conditions
bump golang.org/x/crypto to 0.43.0 (#13518)
* bump golang.org/x/crypto to 0.43.0
CVE-2025-47913 GO-2025-4116

* fixed go.sum

* fixed multiple warnings that prevented test runs

* make generate

* fix lint errors, update linter version

* fix go vet issues
2025-11-18 15:49:03 +05:30

71 lines
2.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package main
import (
"fmt"
"io"
"os"
"strings"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/panicwrap"
)
// This is output if a panic happens.
const panicOutput = `
!!!!!!!!!!!!!!!!!!!!!!!!!!! PACKER CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
Packer crashed! This is always indicative of a bug within Packer.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Packer[1] so that we can fix this.
[1]: https://github.com/hashicorp/packer/issues
!!!!!!!!!!!!!!!!!!!!!!!!!!! PACKER CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
`
// panicHandler is what is called by panicwrap when a panic is encountered
// within Packer. It is guaranteed to run after the resulting process has
// exited so we can take the log file, add in the panic, and store it
// somewhere locally.
func panicHandler(logF *os.File) panicwrap.HandlerFunc {
return func(m string) {
// Write away just output this thing on stderr so that it gets
// shown in case anything below fails.
fmt.Fprintf(os.Stderr, "%s", fmt.Sprintf("%s\n", m))
if err := packer.CheckpointReporter.ReportPanic(m); err != nil {
fmt.Fprintf(os.Stderr, "Failed to report panic. This is safe to ignore: %s", err)
}
// Create the crash log file where we'll write the logs
f, err := os.Create("crash.log")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create crash log file: %s", err)
return
}
defer f.Close()
// Seek the log file back to the beginning
if _, err = logF.Seek(0, 0); err != nil {
fmt.Fprintf(os.Stderr, "Failed to seek log file for crash: %s", err)
return
}
// Copy the contents to the crash file. This will include
// the panic that just happened.
if _, err = io.Copy(f, logF); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write crash log: %s", err)
return
}
// Tell the user a crash occurred in some helpful way that
// they'll hopefully notice.
fmt.Printf("\n\n")
fmt.Println(strings.TrimSpace(panicOutput))
}
}