Skip to content

Commit efb7f1c

Browse files
committed
fix: address PR #224 review feedback
- NotConnected → NotConnectedWrite in all write-requiring handlers - NewNotConnectedMsg constructor for custom hints (cmd_features.go) - Timeout returns ValidationError instead of plain fmt.Errorf - Standardize RawUnitBackend on model.ID - Registry panic prefix corrected to 'registry:' - Full qualified names in AlreadyExists/NotFound messages - Import/export mapping: distinguish not-found from backend errors - Published REST: propagate backend errors, include qualified names
1 parent 5d24fe2 commit efb7f1c

18 files changed

Lines changed: 50 additions & 27 deletions

mdl/backend/infrastructure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type RenameBackend interface {
1919
// manipulate raw BSON (e.g. widget patching, alter page/workflow).
2020
type RawUnitBackend interface {
2121
GetRawUnit(id model.ID) (map[string]any, error)
22-
GetRawUnitBytes(id string) ([]byte, error)
22+
GetRawUnitBytes(id model.ID) ([]byte, error)
2323
ListRawUnitsByType(typePrefix string) ([]*mpr.RawUnit, error)
2424
ListRawUnits(objectType string) ([]*mpr.RawUnitInfo, error)
2525
GetRawUnitByName(objectType, qualifiedName string) (*mpr.RawUnitInfo, error)

mdl/backend/mock/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ type MockBackend struct {
238238

239239
// RawUnitBackend
240240
GetRawUnitFunc func(id model.ID) (map[string]any, error)
241-
GetRawUnitBytesFunc func(id string) ([]byte, error)
241+
GetRawUnitBytesFunc func(id model.ID) ([]byte, error)
242242
ListRawUnitsByTypeFunc func(typePrefix string) ([]*mpr.RawUnit, error)
243243
ListRawUnitsFunc func(objectType string) ([]*mpr.RawUnitInfo, error)
244244
GetRawUnitByNameFunc func(objectType, qualifiedName string) (*mpr.RawUnitInfo, error)
@@ -1574,7 +1574,7 @@ func (m *MockBackend) GetRawUnit(id model.ID) (map[string]any, error) {
15741574
return nil, nil
15751575
}
15761576

1577-
func (m *MockBackend) GetRawUnitBytes(id string) ([]byte, error) {
1577+
func (m *MockBackend) GetRawUnitBytes(id model.ID) ([]byte, error) {
15781578
if m.GetRawUnitBytesFunc != nil {
15791579
return m.GetRawUnitBytesFunc(id)
15801580
}

mdl/backend/mpr/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,8 @@ func (b *MprBackend) RenameDocumentByName(moduleName, oldName, newName string) e
627627
func (b *MprBackend) GetRawUnit(id model.ID) (map[string]any, error) {
628628
return b.reader.GetRawUnit(id)
629629
}
630-
func (b *MprBackend) GetRawUnitBytes(id string) ([]byte, error) {
631-
return b.reader.GetRawUnitBytes(model.ID(id))
630+
func (b *MprBackend) GetRawUnitBytes(id model.ID) ([]byte, error) {
631+
return b.reader.GetRawUnitBytes(id)
632632
}
633633
func (b *MprBackend) ListRawUnitsByType(typePrefix string) ([]*mpr.RawUnit, error) {
634634
return b.reader.ListRawUnitsByType(typePrefix)

mdl/errors/errors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func NewNotConnected() *NotConnectedError {
3333
return &NotConnectedError{msg: "not connected to a project"}
3434
}
3535

36+
// NewNotConnectedMsg creates a NotConnectedError with a custom message.
37+
func NewNotConnectedMsg(msg string) *NotConnectedError {
38+
return &NotConnectedError{msg: msg}
39+
}
40+
3641
// NewNotConnectedWrite creates a NotConnectedError for write access.
3742
func NewNotConnectedWrite() *NotConnectedError {
3843
return &NotConnectedError{WriteMode: true, msg: "not connected to a project in write mode"}

mdl/executor/cmd_dbconnection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (e *Executor) createDatabaseConnection(stmt *ast.CreateDatabaseConnectionSt
4040
return mdlerrors.NewBackend("delete existing connection", err)
4141
}
4242
} else {
43-
return mdlerrors.NewAlreadyExistsMsg("database connection", modName+"."+ex.Name, "use CREATE OR MODIFY to update")
43+
return mdlerrors.NewAlreadyExistsMsg("database connection", modName+"."+ex.Name, fmt.Sprintf("database connection already exists: %s.%s (use CREATE OR MODIFY to update)", modName, ex.Name))
4444
}
4545
}
4646
}

mdl/executor/cmd_enumerations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (e *Executor) execCreateEnumeration(s *ast.CreateEnumerationStmt) error {
3939
// Check if enumeration already exists
4040
existingEnum := e.findEnumeration(s.Name.Module, s.Name.Name)
4141
if existingEnum != nil && !s.CreateOrModify {
42-
return mdlerrors.NewAlreadyExistsMsg("enumeration", s.Name.Module+"."+s.Name.Name, "use CREATE OR MODIFY to update")
42+
return mdlerrors.NewAlreadyExistsMsg("enumeration", s.Name.Module+"."+s.Name.Name, fmt.Sprintf("enumeration already exists: %s.%s (use CREATE OR MODIFY to update)", s.Name.Module, s.Name.Name))
4343
}
4444

4545
// Create enumeration values

mdl/executor/cmd_export_mappings.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ func (e *Executor) describeExportMapping(name ast.QualifiedName) error {
8484

8585
em, err := e.reader.GetExportMappingByQualifiedName(name.Module, name.Name)
8686
if err != nil {
87-
return mdlerrors.NewNotFoundMsg("export mapping", name.String(), err.Error())
87+
if strings.Contains(err.Error(), "not found") {
88+
return mdlerrors.NewNotFound("export mapping", name.String())
89+
}
90+
return mdlerrors.NewBackend("get export mapping", err)
8891
}
8992

9093
if em.Documentation != "" {
@@ -363,7 +366,10 @@ func (e *Executor) execDropExportMapping(s *ast.DropExportMappingStmt) error {
363366

364367
em, err := e.reader.GetExportMappingByQualifiedName(s.Name.Module, s.Name.Name)
365368
if err != nil {
366-
return mdlerrors.NewNotFoundMsg("export mapping", s.Name.String(), err.Error())
369+
if strings.Contains(err.Error(), "not found") {
370+
return mdlerrors.NewNotFound("export mapping", s.Name.String())
371+
}
372+
return mdlerrors.NewBackend("get export mapping", err)
367373
}
368374

369375
if err := e.writer.DeleteExportMapping(em.ID); err != nil {

mdl/executor/cmd_features.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (e *Executor) execShowFeatures(s *ast.ShowFeaturesStmt) error {
7575
default:
7676
// SHOW FEATURES [IN area] — requires project connection
7777
if e.reader == nil {
78-
return mdlerrors.NewNotConnected()
78+
return mdlerrors.NewNotConnectedMsg("not connected to a project\n hint: use SHOW FEATURES FOR VERSION x.y without a project connection")
7979
}
8080
rpv := e.reader.ProjectVersion()
8181
pv = versions.SemVer{Major: rpv.MajorVersion, Minor: rpv.MinorVersion, Patch: rpv.PatchVersion}

mdl/executor/cmd_import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (e *Executor) resolveOneLink(
197197
}
198198

199199
if foundAssoc == nil && foundCross == nil {
200-
return nil, mdlerrors.NewNotFoundMsg("association", link.AssociationName, fmt.Sprintf("not found in module %q", targetModule))
200+
return nil, mdlerrors.NewNotFoundMsg("association", link.AssociationName, fmt.Sprintf("association %q not found in module %q", link.AssociationName, targetModule))
201201
}
202202

203203
// Extract association info

mdl/executor/cmd_import_mappings.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ func (e *Executor) describeImportMapping(name ast.QualifiedName) error {
8484

8585
im, err := e.reader.GetImportMappingByQualifiedName(name.Module, name.Name)
8686
if err != nil {
87-
return mdlerrors.NewNotFoundMsg("import mapping", name.String(), err.Error())
87+
if strings.Contains(err.Error(), "not found") {
88+
return mdlerrors.NewNotFound("import mapping", name.String())
89+
}
90+
return mdlerrors.NewBackend("get import mapping", err)
8891
}
8992

9093
if im.Documentation != "" {
@@ -377,7 +380,10 @@ func (e *Executor) execDropImportMapping(s *ast.DropImportMappingStmt) error {
377380

378381
im, err := e.reader.GetImportMappingByQualifiedName(s.Name.Module, s.Name.Name)
379382
if err != nil {
380-
return mdlerrors.NewNotFoundMsg("import mapping", s.Name.String(), err.Error())
383+
if strings.Contains(err.Error(), "not found") {
384+
return mdlerrors.NewNotFound("import mapping", s.Name.String())
385+
}
386+
return mdlerrors.NewBackend("get import mapping", err)
381387
}
382388

383389
if err := e.writer.DeleteImportMapping(im.ID); err != nil {

0 commit comments

Comments
 (0)