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: stop treating single-arg messages as format strings

Author: pi66
Date: 2026-09-10 21:11
commit: 82b6f311

Info/Warn/Die always ran args[0] through fmt.Sprintf, so any '%'
characters already present in a plain message (e.g. error text
containing Jinja "{% %}" syntax) were misinterpreted as format
verbs, producing garbled "%!s(MISSING)" output. Add a format()
helper that only applies Sprintf when extra args are supplied.

Stat

M src/utils/log/main.go 23 +20 -3

Diff

diff --git a/src/utils/log/main.go b/src/utils/log/main.go
index 173eec1..bf595b7 100644
--- a/src/utils/log/main.go
+++ b/src/utils/log/main.go
@@ -10,6 +10,23 @@ var file io.Writer = os.Stdout

type Title string

+func format(args []any) string { + if len(args) == 0 { + return "" + } + if len(args) == 1 { + if s, ok := args[0].(string); ok { + return s + } + return fmt.Sprint(args[0]) + } + + if s, ok := args[0].(string); ok { ...

Show all

diff --git a/src/utils/log/main.go b/src/utils/log/main.go
index 173eec1..bf595b7 100644
--- a/src/utils/log/main.go
+++ b/src/utils/log/main.go
@@ -10,6 +10,23 @@ var file io.Writer = os.Stdout

type Title string

+func format(args []any) string { + if len(args) == 0 { + return "" + } + if len(args) == 1 { + if s, ok := args[0].(string); ok { + return s + } + return fmt.Sprint(args[0]) + } + + if s, ok := args[0].(string); ok { + return fmt.Sprintf(s, args[1:]...) + } + return fmt.Sprint(args...) +} + func Info(args ...any) { title := "INFO"

@@ -18,7 +35,7 @@ func Info(args ...any) { args = args[1:] }

- msg := fmt.Sprintf(args[0].(string), args[1:]...) + msg := format(args) fmt.Fprintf(file, "[%s]: %s\n", blue(title), msg) }

@@ -30,7 +47,7 @@ func Warn(args ...any) { args = args[1:] }

- msg := fmt.Sprintf(args[0].(string), args[1:]...) + msg := format(args) fmt.Fprintf(file, "[%s]: %s\n", yellow(title), msg) }

@@ -42,7 +59,7 @@ func Die(args ...any) { args = args[1:] }

- msg := fmt.Sprintf(args[0].(string), args[1:]...) + msg := format(args) fmt.Fprintf(file, "[%s]: %s\n", red(title), msg)

os.Exit(1)

// Created by Pi66

// Copyright ©Pi66 2026