fix(cli): report a failed write of the MLX hostfile

The tunnel callback ignored the error of os.WriteFile and set the
hostfile variable even when the file was not written. It now logs the
error and leaves the variable alone.

Assisted-by: Claude Code:claude-sonnet-5-5 go
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto committed 2026-10-21 01:55:12 +00:00
1 parent c8bc964de5
commit 4899713ed7
1 file changed
+4 -1
+4 -1
View File
@@ -382,7 +382,10 @@ func (r *RunCMD) Run(ctx *cliContext.Context) (result error) {
config.WithMLXTunnelCallback(func(tunnels []string) {
hostfile := filepath.Join(os.TempDir(), "localai_mlx_hostfile.json")
data, _ := json.Marshal(tunnels)
os.WriteFile(hostfile, data, 0600)
if err := os.WriteFile(hostfile, data, 0600); err != nil {
xlog.Error("failed to write MLX hostfile", "path", hostfile, "error", err)
return
}
os.Setenv("MLX_DISTRIBUTED_HOSTFILE", hostfile)
xlog.Debug("setting MLX_DISTRIBUTED_HOSTFILE", "value", hostfile, "tunnels", tunnels)
}),