Skip to content

Commit cad1053

Browse files
committed
fix: address PR #224 review feedback
- Include qualified name in AlreadyExists error messages (cmd_dbconnection, cmd_enumerations) - Preserve hint text in NotConnected error for SHOW FEATURES (cmd_features) - Use typed ValidationError for statement timeout (executor.go) - Standardize RawUnitBackend.GetRawUnitBytes to use model.ID (infrastructure.go, mpr/backend, mock/backend) - Fix panic message prefix from 'backend:' to 'registry:' (registry.go) - Add NewNotConnectedMsg constructor (errors.go)
1 parent 5d24fe2 commit cad1053

9 files changed

Lines changed: 15 additions & 10 deletions

File tree

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_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/executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (e *Executor) Execute(stmt ast.Statement) error {
207207
case r := <-ch:
208208
err = r.err
209209
case <-ctx.Done():
210-
err = fmt.Errorf("statement timed out after %v", executeTimeout)
210+
err = mdlerrors.NewValidationf("statement timed out after %v", executeTimeout)
211211
}
212212

213213
if e.logger != nil {

mdl/executor/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func NewRegistry() *Registry {
6363
func (r *Registry) Register(stmt ast.Statement, handler StmtHandler) {
6464
t := reflect.TypeOf(stmt)
6565
if _, exists := r.handlers[t]; exists {
66-
panic(fmt.Sprintf("backend: duplicate handler registration for %s", t))
66+
panic(fmt.Sprintf("registry: duplicate handler registration for %s", t))
6767
}
6868
r.handlers[t] = handler
6969
}

0 commit comments

Comments
 (0)