Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions cli/internal/devserver/filesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading