aboutsummaryrefslogtreecommitdiff
path: root/cmd/vartan/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/vartan/parse.go')
-rw-r--r--cmd/vartan/parse.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/cmd/vartan/parse.go b/cmd/vartan/parse.go
index 8089c5e..ef22ff3 100644
--- a/cmd/vartan/parse.go
+++ b/cmd/vartan/parse.go
@@ -28,6 +28,24 @@ func init() {
}
func runParse(cmd *cobra.Command, args []string) (retErr error) {
+ defer func() {
+ v := recover()
+ if v != nil {
+ err, ok := v.(error)
+ if !ok {
+ retErr = fmt.Errorf("an unexpected error occurred: %v\n", v)
+ fmt.Fprintln(os.Stderr, retErr)
+ return
+ }
+
+ retErr = err
+ }
+
+ if retErr != nil {
+ fmt.Fprintln(os.Stderr, retErr)
+ }
+ }()
+
cgram, err := readCompiledGrammar(args[0])
if err != nil {
return fmt.Errorf("Cannot read a compiled grammar: %w", err)