From 1105a9a174b1eef175dff179153c4d2e631b7b88 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= <bjorn.bidar@jolla.com>
Date: Fri, 29 Mar 2024 15:04:11 +0200
Subject: [PATCH] [sb2] Check if default mode for target exists, error out
 earlier
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Doing so exits with a clearer error message then errors about sb2d
failing to start later such as these:

Runtime-Error loading /tmp/sb2-bidar-20240329-145433.AwoNRb/lua_scripts/init.lua (...dar-20240329-145433.AwoNRb/lua_scripts/argvenvp_misc.lua:28: bad argument #1 to 'files' (/tmp/sb2-bidar-20240329-145433.AwoNRb/wrappers.sdk-build: No such file or directory))
sb2: Error: startup of sb2d failed.

Tested-by: Björn Bidar <bjorn.bidar@jolla.com>
---
 utils/sb2 | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/utils/sb2 b/utils/sb2
index 75ff5152..b2d16313 100755
--- a/utils/sb2
+++ b/utils/sb2
@@ -233,6 +233,10 @@ load_configuration()
 	    exit_error "Cannot access target root '$SBOX_TARGET_ROOT', aborting."
 	fi
 
+	if [ ! -d "$SBOX_DIR/share/scratchbox2/modes/$SBOX_MAPMODE" ]; then
+		exit_error "Configure mode doesn't '$SBOX_MAPMODE' for target doesn't exist, aborting."
+	fi
+
 	LD_LIBRARY_PATH=$saved_LD_LIBRARY_PATH
 
 	# resolve possible symlinks in SBOX_TARGET_ROOT and SBOX_TOOLS_ROOT