Skip to content

Commit e63dd8d

Browse files
committed
fix: enhance backend to send the partial application
Allows the frontend to preserve existing fields when errors occur during application YAML parsing or validation.
1 parent 49831e9 commit e63dd8d

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

cli/internal/devserver/filesync.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ func (fs *SugaFileSync) getApplicationFileContents() (*schema.Application, []byt
4949
if err != nil {
5050
return nil, contents, fmt.Errorf("error parsing application from yaml: %v", err)
5151
} else if schemaResult != nil && len(schemaResult.Errors()) > 0 {
52-
// Wrap the schema errors in a new error
53-
return nil, contents, fmt.Errorf("errors parsing application from yaml: %v", schemaResult.Errors())
52+
// Return partial application along with the error so frontend can preserve existing fields
53+
return application, contents, fmt.Errorf("errors parsing application from yaml: %v", schemaResult.Errors())
5454
}
5555

5656
if appSpecErrors := application.IsValid(); len(appSpecErrors) > 0 {
57-
return nil, contents, fmt.Errorf("application is not valid")
57+
// Return partial application along with the error so frontend can preserve existing fields
58+
return application, contents, fmt.Errorf("application is not valid")
5859
}
5960

6061
return application, contents, nil
@@ -95,11 +96,19 @@ func validateApplicationSchema(contents []byte) ([]schema.ValidationError, error
9596
func (fs *SugaFileSync) OnConnect(send SendFunc) {
9697
application, contents, err := fs.getApplicationFileContents()
9798
if err != nil {
98-
validationErrors, err := validateApplicationSchema(contents)
99-
if err != nil {
99+
validationErrors, validationErr := validateApplicationSchema(contents)
100+
if validationErr != nil {
100101
return
101102
}
102103

104+
// Send partial application data first so frontend has existing fields to merge with
105+
if application != nil {
106+
send(Message[any]{
107+
Type: "syncMessage",
108+
Payload: *application,
109+
})
110+
}
111+
103112
send(Message[any]{
104113
Type: "syncError",
105114
Payload: validationErrors,
@@ -210,11 +219,19 @@ func (fs *SugaFileSync) watchFile() error {
210219

211220
fileError = err
212221

213-
validationErrors, err := validateApplicationSchema(contents)
214-
if err != nil {
222+
validationErrors, validationErr := validateApplicationSchema(contents)
223+
if validationErr != nil {
215224
return
216225
}
217226

227+
// Send partial application data first so frontend has existing fields to merge with
228+
if application != nil {
229+
fs.broadcast(Message[any]{
230+
Type: "syncMessage",
231+
Payload: *application,
232+
})
233+
}
234+
218235
fs.broadcast(Message[any]{
219236
Type: "syncError",
220237
Payload: validationErrors,

0 commit comments

Comments
 (0)