Skip to content

Commit d23aacd

Browse files
committed
Show more info when recovering from panic
1 parent 4b918bb commit d23aacd

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

apisprout.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"context"
55
"encoding/json"
6-
"errors"
76
"fmt"
87
"io/ioutil"
98
"log"
@@ -21,6 +20,7 @@ import (
2120
"github.com/getkin/kin-openapi/openapi3"
2221
"github.com/getkin/kin-openapi/openapi3filter"
2322
"github.com/gobwas/glob"
23+
"github.com/pkg/errors"
2424
"github.com/spf13/cobra"
2525
"github.com/spf13/pflag"
2626
"github.com/spf13/viper"
@@ -221,7 +221,11 @@ func load(uri string, data []byte) (swagger *openapi3.Swagger, router *openapi3f
221221
if r := recover(); r != nil {
222222
swagger = nil
223223
router = nil
224-
err = fmt.Errorf("Caught panic while trying to load")
224+
if e, ok := r.(error); ok {
225+
err = errors.Wrap(e, "Caught panic while trying to load")
226+
} else {
227+
err = fmt.Errorf("Caught panic while trying to load")
228+
}
225229
}
226230
}()
227231

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/magiconair/properties v1.8.0
1616
github.com/mitchellh/mapstructure v1.1.2
1717
github.com/pelletier/go-toml v1.2.0
18+
github.com/pkg/errors v0.8.1
1819
github.com/pmezard/go-difflib v1.0.0
1920
github.com/spf13/afero v1.2.1
2021
github.com/spf13/cast v1.3.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz
3434
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
3535
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
3636
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
37+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
38+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3739
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3840
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3941
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=

0 commit comments

Comments
 (0)