Skip to content

Commit b9bfd86

Browse files
committed
init as empty slice
1 parent e4b0b6e commit b9bfd86

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

internal/stack/stack.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func Load(gitDir string) (*StackFile, error) {
149149
if errors.Is(err, os.ErrNotExist) {
150150
return &StackFile{
151151
SchemaVersion: schemaVersion,
152+
Stacks: []Stack{},
152153
}, nil
153154
}
154155
return nil, fmt.Errorf("reading stack file: %w", err)
@@ -165,6 +166,9 @@ func Load(gitDir string) (*StackFile, error) {
165166
// Save writes the stack file to the given git directory.
166167
func Save(gitDir string, sf *StackFile) error {
167168
sf.SchemaVersion = schemaVersion
169+
if sf.Stacks == nil {
170+
sf.Stacks = []Stack{}
171+
}
168172
data, err := json.MarshalIndent(sf, "", " ")
169173
if err != nil {
170174
return fmt.Errorf("marshaling stack file: %w", err)

0 commit comments

Comments
 (0)