From 256989f4a37e7b124c0684aab0f34cf5e09559be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sun, 23 Jun 2024 16:13:52 +0200 Subject: [PATCH] fix: error early when the image write fails (#34) Closes #33 --- hcloudimages/client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hcloudimages/client.go b/hcloudimages/client.go index 5205b77..abeb24e 100644 --- a/hcloudimages/client.go +++ b/hcloudimages/client.go @@ -299,6 +299,10 @@ func (s *Client) Upload(ctx context.Context, options UploadOptions) (*hcloud.Ima } cmd += "dd of=/dev/sda bs=4M && sync" + + // Make sure that we fail early, ie. if the image url does not work. + // the pipefail does not work correctly without wrapping in bash. + cmd = fmt.Sprintf("bash -c 'set -euo pipefail && %s'", cmd) logger.DebugContext(ctx, "running download, decompress and write to disk command", "cmd", cmd) output, err := sshsession.Run(sshClient, cmd, options.ImageReader)