Skip to content

Commit 508fdfb

Browse files
mcanevetclaude
andcommitted
fix: print new flag errors to stderr and strip whitespace from base64
- Validation errors for -config-env, -config-env-base64 now print to stderr and exit 1 instead of going to log.Fatal (which adds a timestamp prefix) or silently returning 0. - Strip surrounding whitespace from the env var value before base64 decoding to tolerate line-folding by template engines. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Mickaël Canévet <mickael.canevet@proton.ch>
1 parent 12cd9bf commit 508fdfb

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"log"
1111
"os"
12+
"strings"
1213

1314
"github.com/siderolabs/go-adv/adv/talos"
1415
"github.com/siderolabs/go-blockdevice/v2/block"
@@ -110,14 +111,16 @@ func main() {
110111
}
111112

112113
if *configPath == "" && *configEnv == "" {
113-
fmt.Println("Usage: talos-meta-tool -device <disk-device> (-config <file> | -config-env <VAR> [-config-env-base64])")
114-
return
114+
fmt.Fprintln(os.Stderr, "Usage: talos-meta-tool -device <disk-device> (-config <file> | -config-env <VAR> [-config-env-base64])")
115+
os.Exit(1)
115116
}
116117
if *configPath != "" && *configEnv != "" {
117-
log.Fatal("-config and -config-env are mutually exclusive")
118+
fmt.Fprintln(os.Stderr, "-config and -config-env are mutually exclusive")
119+
os.Exit(1)
118120
}
119121
if *configEnvBase64 && *configEnv == "" {
120-
log.Fatal("-config-env-base64 requires -config-env")
122+
fmt.Fprintln(os.Stderr, "-config-env-base64 requires -config-env")
123+
os.Exit(1)
121124
}
122125

123126
device, err := os.OpenFile(*devicePath, os.O_RDWR, 0)
@@ -138,7 +141,7 @@ func main() {
138141
log.Fatalf("environment variable %q is not set", *configEnv)
139142
}
140143
if *configEnvBase64 {
141-
configData, err = base64.StdEncoding.DecodeString(val)
144+
configData, err = base64.StdEncoding.DecodeString(strings.TrimSpace(val))
142145
if err != nil {
143146
log.Fatalf("base64 decoding %q: %v", *configEnv, err)
144147
}

0 commit comments

Comments
 (0)