Skip to content

Commit bd7c55f

Browse files
feat: handle empty stack in preview (#1423)
* feat: handle empty stack in preview Signed-off-by: 7h3-3mp7y-m4n <emailtorash@gmail.com>
1 parent b77573a commit bd7c55f

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

pkg/cmd/preview/preview.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,17 @@ func (o *PreviewOptions) Run() error {
240240
return err
241241
}
242242

243-
// return immediately if no resource found in stack
244-
if spec == nil || len(spec.Resources) == 0 {
243+
if spec == nil {
245244
if o.Output != jsonOutput {
246-
fmt.Println(pretty.GreenBold("\nNo resource found in this stack."))
245+
fmt.Println(pretty.YellowBold("\nSpec is nil. Treating as empty spec."))
246+
}
247+
spec = &apiv1.Spec{}
248+
}
249+
250+
if len(spec.Resources) == 0 {
251+
if o.Output != jsonOutput {
252+
fmt.Println(pretty.YellowBold("\nNo resources found in the spec."))
247253
}
248-
return nil
249254
}
250255

251256
// compute state

pkg/server/manager/stack/execute.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,13 @@ func (m *StackManager) PreviewStack(ctx context.Context, params *StackRequestPar
198198
return nil, err
199199
}
200200

201-
// return immediately if no resource found in stack
202-
// todo: if there is no resource, should still do diff job; for now, if output is json format, there is no hint
203-
if sp == nil || len(sp.Resources) == 0 {
204-
logutil.LogToAll(logger, runLogger, "Info", "No resource change found in this stack...")
205-
return nil, nil
201+
// Treat nil spec as empty and continue with diff
202+
if sp == nil {
203+
logutil.LogToAll(logger, runLogger, "Warn", "Generated spec is nil, treating as empty spec...")
204+
sp = &apiv1.Spec{}
205+
}
206+
if len(sp.Resources) == 0 {
207+
logutil.LogToAll(logger, runLogger, "Info", "No resources found in spec. Proceeding with full diff.")
206208
}
207209

208210
// Preview

0 commit comments

Comments
 (0)