From 89d5fc91b0a13dd045744e3fc82ec319d1d41610 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 1 Oct 2025 11:48:51 +0200 Subject: [PATCH] fix: gracefully explode of missing context See https://git.coopcloud.tech/toolshed/abra/issues/675 --- pkg/client/client.go | 7 +++++++ tests/integration/app_deploy.bats | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/client/client.go b/pkg/client/client.go index 69cc53a6..d1ddb438 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -6,9 +6,11 @@ import ( "errors" "net/http" "os" + "path" "strings" "time" + "coopcloud.tech/abra/pkg/config" contextPkg "coopcloud.tech/abra/pkg/context" "coopcloud.tech/abra/pkg/i18n" "coopcloud.tech/abra/pkg/log" @@ -41,6 +43,11 @@ func New(serverName string, opts ...Opt) (*client.Client, error) { ctx, err := GetContext(serverName) if err != nil { + serverDir := path.Join(config.SERVERS_DIR, serverName) + if _, err := os.Stat(serverDir); err == nil { + return nil, errors.New(i18n.G("server missing context, run \"abra server add %s\"?", serverName)) + } + return nil, errors.New(i18n.G("unknown server, run \"abra server add %s\"?", serverName)) } diff --git a/tests/integration/app_deploy.bats b/tests/integration/app_deploy.bats index bb39b716..b582b222 100644 --- a/tests/integration/app_deploy.bats +++ b/tests/integration/app_deploy.bats @@ -577,3 +577,18 @@ teardown(){ assert_success refute_output --partial "IMAGES" } + +# bats test_tags=slow +@test "manually created server without context bails gracefully" { + run mkdir -p "$ABRA_DIR/servers/default2" + assert_success + assert_exists "$ABRA_DIR/servers/default2" + + run cp "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" "$ABRA_DIR/servers/default2/$TEST_APP_DOMAIN_2.env" + assert_success + assert_exists "$ABRA_DIR/servers/default2/$TEST_APP_DOMAIN_2.env" + + run $ABRA app deploy "$TEST_APP_DOMAIN_2" --no-input --no-converge-checks + assert_failure + assert_output --partial "server missing context" +}