From 44a3b3bbd1b8b7c11eed7cce9a07aa4c07cdb90e Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 28 Apr 2024 19:49:40 +0200 Subject: builder: return errors instead of panicking --- internal/builder/builder.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'internal') diff --git a/internal/builder/builder.go b/internal/builder/builder.go index 88e3f02..90e957c 100644 --- a/internal/builder/builder.go +++ b/internal/builder/builder.go @@ -3,7 +3,6 @@ package builder import ( "fmt" "io" - "log" "log/slog" "net/url" "os" @@ -175,21 +174,21 @@ func build(outDir string, config config.Config) error { func BuildSite(ioConfig IOConfig) error { config, err := config.GetConfig() if err != nil { - log.Panic(errors.Errorf("could not get config: %v", err)) + return errors.WithMessage(err, "could not get config") } config.InjectLiveReload = ioConfig.Development if ioConfig.BaseURL.URL != nil { config.BaseURL.URL, err = url.Parse(ioConfig.BaseURL.String()) if err != nil { - log.Panic(errors.Errorf("highly unlikely: %v", err)) + return errors.WithMessage(err, "could not re-parse base URL") } } if ioConfig.Development && ioConfig.Destination != "website" { err = os.RemoveAll(ioConfig.Destination) if err != nil { - log.Panic(errors.Errorf("could not remove destination directory: %v", err)) + return errors.WithMessage(err, "could not remove destination directory") } } -- cgit 1.4.1