fix: gracefully explode of missing context

See #675
This commit is contained in:
2025-10-01 11:48:51 +02:00
parent 5af3c5f56e
commit 89d5fc91b0
2 changed files with 22 additions and 0 deletions

View File

@ -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))
}

View File

@ -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"
}