Pi66

Home | Repos | About | Blog | Gaza

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

About | Files | Commits | Refs | License


fix: handle errors in main() instead of letting them panic

Author: pi66
Date: 2026-10-05 19:10
commit: 1b32b158

Stat

M src/main.go 12 +5 -7

Diff

diff --git a/src/main.go b/src/main.go
index d145703..6abb369 100644
--- a/src/main.go
+++ b/src/main.go
@@ -12,13 +12,11 @@ import (
 const VERSION = "0.5.2"

func main() { - if err := run(os.Args[1:]); err != nil { - log.Die(err.Error()) - } -} - -func run(args []string) (err error) { - defer Handle(&err) + args := os.Args[1:] + var err error + defer Handle(&err, func(err *error) { + log.Die((*err).Error()) + }) ...

Show all

diff --git a/src/main.go b/src/main.go
index d145703..6abb369 100644
--- a/src/main.go
+++ b/src/main.go
@@ -12,13 +12,11 @@ import (
 const VERSION = "0.5.2"

func main() { - if err := run(os.Args[1:]); err != nil { - log.Die(err.Error()) - } -} - -func run(args []string) (err error) { - defer Handle(&err) + args := os.Args[1:] + var err error + defer Handle(&err, func(err *error) { + log.Die((*err).Error()) + })

if len(args) == 0 {
	utils.PrintHelp()

// Created by Pi66

// Copyright ©Pi66 2026