Replace panics with error logs

This commit is contained in:
Elara 2023-01-07 15:25:18 -08:00
parent 4ae5f8d387
commit d7ad5f9f94
3 changed files with 43 additions and 7 deletions

View File

@ -10,8 +10,14 @@ import (
"go.arsenm.dev/go-lemmy/cmd/gen/generator"
"go.arsenm.dev/go-lemmy/cmd/gen/parser"
"go.arsenm.dev/logger"
"go.arsenm.dev/logger/log"
)
func init() {
log.Logger = logger.NewPretty(os.Stderr)
}
var implDirs = [...]string{
"crates/api_crud/src",
"crates/apub/src/api",
@ -97,7 +103,7 @@ func main() {
return generator.NewStruct(outFl, "types").Generate(fileStructs)
})
if err != nil {
panic(err)
log.Fatal("Error walking directory while parsing structs").Err(err).Str("dir", dir).Send()
}
}
@ -136,36 +142,36 @@ func main() {
return nil
})
if err != nil {
panic(err)
log.Fatal("Error walking directory while parsing impls").Err(err).Str("dir", dir).Send()
}
}
routesPath := filepath.Join(*lemmyDir, routesFile)
rf, err := os.Open(routesPath)
if err != nil {
panic(err)
log.Fatal("Error opening routes file").Err(err).Send()
}
defer rf.Close()
rp := parser.NewRoutes(rf)
routes, err := rp.Parse()
if err != nil {
panic(err)
log.Fatal("Error parsing routes file").Err(err).Send()
}
orf, err := os.Create(filepath.Join(*outDir, "routes.gen.go"))
if err != nil {
panic(err)
log.Fatal("Error creating routes output file").Err(err).Send()
}
defer orf.Close()
_, err = orf.WriteString("// Source: " + routesPath + "\n")
if err != nil {
panic(err)
log.Fatal("Error writing source string to routes file").Err(err).Send()
}
err = generator.NewRoutes(orf, "lemmy").Generate(routes, impls)
if err != nil {
panic(err)
log.Fatal("Error generating output routes file").Err(err).Send()
}
}

8
go.mod
View File

@ -8,5 +8,13 @@ require (
github.com/dave/jennifer v1.6.0
github.com/google/go-querystring v1.1.0
github.com/gorilla/websocket v1.4.2
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304
)
require (
github.com/gookit/color v1.5.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/sys v0.1.0 // indirect
)

22
go.sum
View File

@ -1,11 +1,33 @@
github.com/dave/jennifer v1.6.0 h1:MQ/6emI2xM7wt0tJzJzyUik2Q3Tcn2eE0vtYgh4GPVI=
github.com/dave/jennifer v1.6.0/go.mod h1:AxTG893FiZKqxy3FP1kL80VMshSMuz2G+EgvszgGRnk=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df h1:8mBHvEe7BJmpOeKSMA5YLqrGo9dCpePocTeR0C1+/2w=
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw=
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304 h1:YUqj+XKtfrn3kXjFIiZ8jwKROD7ioAOOHUuo3ZZ2opc=
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=