11import { Effect , Match , Option } from "effect" ;
2- import type { StackError , StackId } from "@supabase/stack/effect" ;
2+ import type { StackDescriptor , StackError , StackId } from "@supabase/stack/effect" ;
33import { Output } from "../../../../shared/output/output.service.ts" ;
44import { OutputFlag } from "../../../../command-internal/global-flags.ts" ;
55import { CommandSettings } from "../../../../config/command-settings.service.ts" ;
@@ -13,7 +13,6 @@ import {
1313 validateStackId ,
1414 validateStackTarget ,
1515} from "../stack.shared.ts" ;
16- import { loadStackConfig } from "../stack-config.ts" ;
1716import type { StackRestartFlags } from "./restart.command.ts" ;
1817import { StackCommandRestartError } from "./restart.errors.ts" ;
1918
@@ -32,7 +31,7 @@ const mapStackError = (error: StackError) => {
3231 Match . tag ( "PortUnavailableError" , "PortAllocationError" , ( ) => ( {
3332 reason : "port" as const ,
3433 suggestion :
35- "Free the conflicting port or update the local stack port configuration, then retry ." ,
34+ "Free the conflicting port and retry, or stop the stack and use supabase stack start to apply updated project port configuration ." ,
3635 } ) ) ,
3736 Match . tag (
3837 "InvalidStackConfigError" ,
@@ -72,6 +71,14 @@ const mapStackError = (error: StackError) => {
7271 reason : "artifact" as const ,
7372 suggestion : "Retry the stack restart with --debug if the artifact cannot be prepared." ,
7473 } ) ) ,
74+ Match . tag ( "StackRuntimeError" , ( ) => ( {
75+ reason : "unknown" as const ,
76+ suggestion : "Retry the stack restart with --debug and inspect the runtime diagnostics." ,
77+ } ) ) ,
78+ Match . tag ( "StackCleanupError" , ( ) => ( {
79+ reason : "unknown" as const ,
80+ suggestion : "Retry the stack restart with --debug and inspect cleanup diagnostics." ,
81+ } ) ) ,
7582 Match . orElse ( ( ) => ( { reason : "unknown" as const } ) ) ,
7683 ) ;
7784 return new StackCommandRestartError ( {
@@ -96,13 +103,12 @@ export const stackRestart = Effect.fn("experimental.stack.restart")(function* (
96103 stackId : Option . getOrUndefined ( flags . stackId ) ,
97104 } ) . pipe ( Effect . mapError ( mapTargetError ) ) ;
98105
99- let target : { readonly projectRoot : string ; readonly id : StackId } ;
106+ let id : StackId ;
107+ let desiredLifecycle : StackDescriptor [ "desiredLifecycle" ] ;
100108 if ( Option . isSome ( flags . stackId ) ) {
101- const validId = yield * validateStackId ( flags . stackId . value ) . pipe (
102- Effect . mapError ( mapTargetError ) ,
103- ) ;
104- const inspection = yield * api . inspectStack ( validId ) . pipe ( Effect . mapError ( mapStackError ) ) ;
105- target = { projectRoot : inspection . descriptor . projectRoot , id : inspection . descriptor . id } ;
109+ id = yield * validateStackId ( flags . stackId . value ) . pipe ( Effect . mapError ( mapTargetError ) ) ;
110+ const inspection = yield * api . inspectStack ( id ) . pipe ( Effect . mapError ( mapStackError ) ) ;
111+ desiredLifecycle = inspection . descriptor . desiredLifecycle ;
106112 } else {
107113 const found = yield * api
108114 . findStack ( {
@@ -120,30 +126,22 @@ export const stackRestart = Effect.fn("experimental.stack.restart")(function* (
120126 ? "Choose an existing --stack name or omit --stack for the current project."
121127 : "Run supabase stack start first." ,
122128 } ) ;
123- target = { projectRoot : found . value . projectRoot , id : found . value . id } ;
129+ id = found . value . id ;
130+ desiredLifecycle = found . value . desiredLifecycle ;
124131 }
125- const config = yield * loadStackConfig ( target . projectRoot ) . pipe (
126- Effect . mapError (
127- ( error ) =>
128- new StackCommandRestartError ( {
129- reason : "invalid-config" ,
130- message : error . message ,
131- cause : error ,
132- } ) ,
133- ) ,
134- ) ;
135- const stack = yield * api . openStack ( target . id ) . pipe ( Effect . mapError ( mapStackError ) ) ;
136- const task = yield * output . task ( "Preparing local Supabase stack..." ) ;
137- yield * stack . prepare ( { config } ) . pipe (
138- Effect . mapError ( mapStackError ) ,
139- Effect . tapError ( ( error ) => task . fail ( error . message ) ) ,
140- ) ;
141- yield * task . message ( "Restarting local Supabase stack..." ) ;
132+ if ( desiredLifecycle === "unconfigured" )
133+ return yield * new StackCommandRestartError ( {
134+ reason : "lifecycle" ,
135+ message : "The selected stack has not been configured yet." ,
136+ suggestion : "Run supabase stack start to configure the stack first." ,
137+ } ) ;
138+ const stack = yield * api . openStack ( id ) . pipe ( Effect . mapError ( mapStackError ) ) ;
139+ const task = yield * output . task ( "Restarting local Supabase stack..." ) ;
142140 yield * stack . stop . pipe (
143141 Effect . mapError ( mapStackError ) ,
144142 Effect . tapError ( ( error ) => task . fail ( error . message ) ) ,
145143 ) ;
146- const status = yield * stack . start ( { config } ) . pipe (
144+ const status = yield * stack . start ( ) . pipe (
147145 Effect . mapError ( mapStackError ) ,
148146 Effect . tapError ( ( error ) => task . fail ( error . message ) ) ,
149147 Effect . tap ( ( ) => task . clear ( ) ) ,
0 commit comments