From e63dd8d8534ee2987a66cb2883a0a32dc293f9b4 Mon Sep 17 00:00:00 2001 From: Rak Siva Date: Fri, 28 Nov 2025 13:47:17 +1000 Subject: [PATCH] fix: enhance backend to send the partial application Allows the frontend to preserve existing fields when errors occur during application YAML parsing or validation. --- cli/internal/devserver/filesync.go | 31 +++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/cli/internal/devserver/filesync.go b/cli/internal/devserver/filesync.go index 3b774181..3ba0a636 100644 --- a/cli/internal/devserver/filesync.go +++ b/cli/internal/devserver/filesync.go @@ -49,12 +49,13 @@ func (fs *SugaFileSync) getApplicationFileContents() (*schema.Application, []byt if err != nil { return nil, contents, fmt.Errorf("error parsing application from yaml: %v", err) } else if schemaResult != nil && len(schemaResult.Errors()) > 0 { - // Wrap the schema errors in a new error - return nil, contents, fmt.Errorf("errors parsing application from yaml: %v", schemaResult.Errors()) + // Return partial application along with the error so frontend can preserve existing fields + return application, contents, fmt.Errorf("errors parsing application from yaml: %v", schemaResult.Errors()) } if appSpecErrors := application.IsValid(); len(appSpecErrors) > 0 { - return nil, contents, fmt.Errorf("application is not valid") + // Return partial application along with the error so frontend can preserve existing fields + return application, contents, fmt.Errorf("application is not valid") } return application, contents, nil @@ -95,11 +96,19 @@ func validateApplicationSchema(contents []byte) ([]schema.ValidationError, error func (fs *SugaFileSync) OnConnect(send SendFunc) { application, contents, err := fs.getApplicationFileContents() if err != nil { - validationErrors, err := validateApplicationSchema(contents) - if err != nil { + validationErrors, validationErr := validateApplicationSchema(contents) + if validationErr != nil { return } + // Send partial application data first so frontend has existing fields to merge with + if application != nil { + send(Message[any]{ + Type: "syncMessage", + Payload: *application, + }) + } + send(Message[any]{ Type: "syncError", Payload: validationErrors, @@ -210,11 +219,19 @@ func (fs *SugaFileSync) watchFile() error { fileError = err - validationErrors, err := validateApplicationSchema(contents) - if err != nil { + validationErrors, validationErr := validateApplicationSchema(contents) + if validationErr != nil { return } + // Send partial application data first so frontend has existing fields to merge with + if application != nil { + fs.broadcast(Message[any]{ + Type: "syncMessage", + Payload: *application, + }) + } + fs.broadcast(Message[any]{ Type: "syncError", Payload: validationErrors,