Skip to content

Commit

Permalink
Print a stack trace on panic
Browse files Browse the repository at this point in the history
  • Loading branch information
nihei9 committed Aug 5, 2021
1 parent 7b4ed66 commit 3d417d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cmd/vartan/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime/debug"
"strings"

verr "github.com/nihei9/vartan/error"
Expand Down Expand Up @@ -46,8 +47,8 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) {
if v != nil {
err, ok := v.(error)
if !ok {
retErr = fmt.Errorf("an unexpected error occurred: %v\n", v)
fmt.Fprintln(os.Stderr, retErr)
retErr = fmt.Errorf("an unexpected error occurred: %v", v)
fmt.Fprintf(os.Stderr, "%v:\n%v", retErr, string(debug.Stack()))
return
}

Expand All @@ -67,7 +68,8 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) {
}
}
}
fmt.Fprintln(os.Stderr, retErr)

fmt.Fprintf(os.Stderr, "%v:\n%v", retErr, string(debug.Stack()))
}
}()

Expand Down
7 changes: 4 additions & 3 deletions cmd/vartan/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime/debug"

"github.com/nihei9/vartan/driver"
"github.com/nihei9/vartan/spec"
Expand Down Expand Up @@ -37,16 +38,16 @@ func runParse(cmd *cobra.Command, args []string) (retErr error) {
if v != nil {
err, ok := v.(error)
if !ok {
retErr = fmt.Errorf("an unexpected error occurred: %v\n", v)
fmt.Fprintln(os.Stderr, retErr)
retErr = fmt.Errorf("an unexpected error occurred: %v", v)
fmt.Fprintf(os.Stderr, "%v:\n%v", retErr, string(debug.Stack()))
return
}

retErr = err
}

if retErr != nil {
fmt.Fprintln(os.Stderr, retErr)
fmt.Fprintf(os.Stderr, "%v:\n%v", retErr, string(debug.Stack()))
}
}()

Expand Down

0 comments on commit 3d417d5

Please sign in to comment.