feat: add typed error system for executor#222
Conversation
AI Code ReviewCritical Issues
Moderate Issues
Minor Issues
What Looks Good
RecommendationApprove. This PR successfully implements a typed error system for the executor that enables programmatic error classification while maintaining complete backward compatibility. The change is well-scoped, thoroughly tested, and follows Go error handling best practices. The migration appears complete and correct based on spot-checking multiple conversions. Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
There was a problem hiding this comment.
Pull request overview
This PR introduces a new structured error package for the MDL executor and migrates executor commands/helpers away from ad-hoc fmt.Errorf strings to typed errors that can be classified programmatically (primarily via errors.As, and optionally errors.Is if implemented consistently).
Changes:
- Add
mdl/errorspackage with structured error types and contract tests. - Migrate many executor error returns to
mdlerrorstyped constructors (NewNotConnected,NewNotFound,NewAlreadyExists,NewValidation,NewUnsupported,NewBackend) and re-exportErrExit. - Apply a number of
gofmt/alignment-only changes across SDK/model/AST files.
Reviewed changes
Copilot reviewed 83 out of 96 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/pages/pages_datasources.go | gofmt/alignment only. |
| sdk/mpr/writer_rest.go | gofmt/alignment only. |
| sdk/mpr/writer_datatransformer.go | gofmt/alignment only. |
| sdk/mpr/parser_customblob.go | gofmt/alignment only. |
| sdk/microflows/microflows_actions.go | gofmt/alignment only. |
| sdk/agenteditor/types.go | gofmt/alignment only. |
| model/types.go | gofmt/alignment only. |
| mdl/executor/widget_registry.go | Replace fmt.Errorf with typed backend/validation errors for widget definition loading/validation. |
| mdl/executor/widget_property.go | Use typed validation/not-found errors for widget property updates. |
| mdl/executor/widget_engine.go | Replace widget build/resolve errors with typed backend/validation/not-found errors. |
| mdl/executor/validate.go | Convert validation-time errors to typed not-connected/not-found/validation errors. |
| mdl/executor/theme_reader.go | Wrap theme registry I/O failures as typed backend errors. |
| mdl/executor/output_guard.go | Convert line-limit abort to typed validation error. |
| mdl/executor/oql_type_inference.go | Convert entity lookup failure to typed not-found error. |
| mdl/executor/helpers.go | Convert module/folder lookup and cache errors to typed validation/backend/not-found errors. |
| mdl/executor/fragment_test.go | Update test expectation to new “already exists” wording. |
| mdl/executor/executor_query.go | Convert not-connected/unsupported query errors to typed errors. |
| mdl/executor/executor_dispatch.go | Convert unknown statement type to typed unsupported error. |
| mdl/executor/executor_connect.go | Convert connect/reconnect failures to typed backend/not-connected errors. |
| mdl/executor/executor.go | Wrap finalization reconcile failure as typed backend error. |
| mdl/executor/cmd_workflows_write.go | Convert workflow create/drop errors to typed errors. |
| mdl/executor/cmd_workflows.go | Convert workflow list/describe errors to typed backend/not-found errors. |
| mdl/executor/cmd_widgets.go | Convert widget show/update errors to typed backend/not-connected/unsupported errors. |
| mdl/executor/cmd_styling.go | Convert styling show/describe/alter errors to typed errors. |
| mdl/executor/cmd_structure.go | Convert structure/catalog/hierarchy errors to typed backend/not-connected errors. |
| mdl/executor/cmd_sql.go | Convert SQL connection/parse failures to typed not-found/backend errors. |
| mdl/executor/cmd_snippets.go | Convert snippet listing errors to typed backend errors. |
| mdl/executor/cmd_security.go | Convert security show/describe errors to typed validation/backend/not-found/unsupported errors. |
| mdl/executor/cmd_search.go | Convert search query argument and DB errors to typed validation/backend errors. |
| mdl/executor/cmd_rest_clients.go | Convert REST client show/create/drop errors to typed errors. |
| mdl/executor/cmd_rename.go | Convert rename errors to typed not-connected/backend/not-found/unsupported errors. |
| mdl/executor/cmd_published_rest.go | Convert published REST show/create/alter/drop errors to typed errors. |
| mdl/executor/cmd_pages_show.go | Convert page listing errors to typed backend errors. |
| mdl/executor/cmd_pages_describe.go | Convert page/snippet/layout describe errors to typed backend/not-found errors. |
| mdl/executor/cmd_pages_create_v3.go | Convert V3 page/snippet create/replace errors to typed errors. |
| mdl/executor/cmd_pages_builder_v3_widgets.go | Convert widget-builder failures to typed backend/validation/not-found errors. |
| mdl/executor/cmd_pages_builder_v3_pluggable.go | Convert attribute path validation error to typed validation error. |
| mdl/executor/cmd_pages_builder_input.go | Convert ref resolution errors to typed validation/backend/not-found errors. |
| mdl/executor/cmd_pages_builder.go | Convert page builder init/resolve/drop errors to typed backend/not-found/already-exists errors. |
| mdl/executor/cmd_page_wireframe.go | Convert wireframe generation errors to typed errors. |
| mdl/executor/cmd_oql_plan.go | Convert JSON marshal failure to typed backend error. |
| mdl/executor/cmd_navigation.go | Convert navigation update errors to typed errors. |
| mdl/executor/cmd_modules.go | Convert module create/drop/show/describe errors to typed errors. |
| mdl/executor/cmd_module_overview.go | Convert module overview errors to typed backend/not-connected errors. |
| mdl/executor/cmd_misc.go | Re-export ErrExit from mdl/errors and convert misc command errors to typed errors in several places. |
| mdl/executor/cmd_microflows_show.go | Convert microflow/nanoflow show/describe errors to typed backend/not-found errors. |
| mdl/executor/cmd_microflows_drop.go | Convert microflow drop errors to typed not-connected-write/backend/not-found errors. |
| mdl/executor/cmd_microflows_create.go | Convert microflow create-time errors to typed errors (entity/enumeration resolution, create/update). |
| mdl/executor/cmd_microflows_builder.go | gofmt/alignment only. |
| mdl/executor/cmd_microflow_elk.go | Convert ELK generation errors to typed errors. |
| mdl/executor/cmd_mermaid.go | Convert Mermaid describe errors to typed not-connected/backend/unsupported/not-found errors. |
| mdl/executor/cmd_lint.go | Convert lint preconditions and failures to typed errors. |
| mdl/executor/cmd_layouts.go | Convert layout listing errors to typed backend errors. |
| mdl/executor/cmd_languages.go | Convert catalog precondition/query failures to typed validation/backend errors. |
| mdl/executor/cmd_jsonstructures.go | Convert JSON structure CRUD/list errors to typed errors. |
| mdl/executor/cmd_javascript_actions.go | Convert JS action show/describe errors to typed backend/not-found errors. |
| mdl/executor/cmd_javaactions.go | Convert Java action CRUD/show/describe errors to typed errors. |
| mdl/executor/cmd_import_mappings.go | Convert import mapping show/describe/create/drop errors to typed errors. |
| mdl/executor/cmd_import.go | Convert import execution/link resolution errors to typed validation/backend/not-found/unsupported errors. |
| mdl/executor/cmd_imagecollections.go | Convert image collection CRUD/show/describe errors to typed errors. |
| mdl/executor/cmd_fragments.go | Convert fragment define/describe errors to typed already-exists/not-found errors. |
| mdl/executor/cmd_folders.go | Convert folder lookup/drop/move errors to typed errors. |
| mdl/executor/cmd_features.go | Convert feature checking/showing errors to typed backend/unsupported errors. |
| mdl/executor/cmd_export_mappings.go | Convert export mapping show/describe/create/drop errors to typed errors. |
| mdl/executor/cmd_enumerations.go | Convert enumeration CRUD/list/describe errors to typed errors. |
| mdl/executor/cmd_entities_describe.go | Convert entity show/describe errors to typed validation/backend/not-found errors. |
| mdl/executor/cmd_domainmodel_elk.go | Convert domain model ELK errors to typed errors. |
| mdl/executor/cmd_diff_local.go | Convert diff-local preconditions and git/file failures to typed errors. |
| mdl/executor/cmd_diff.go | Convert diff precondition error to typed not-connected error. |
| mdl/executor/cmd_dbconnection.go | Convert DB connection CRUD/show/describe errors to typed errors. |
| mdl/executor/cmd_datatransformer.go | Convert data transformer list/describe/create/drop errors to typed errors. |
| mdl/executor/cmd_contract.go | Convert contract parsing/describe/create external entities errors to typed errors. |
| mdl/executor/cmd_context.go | Convert show-context input/not-found errors to typed validation/not-found errors. |
| mdl/executor/cmd_constants.go | Convert constant CRUD/show/describe errors to typed errors. |
| mdl/executor/cmd_catalog.go | Convert catalog build/query/describe/search errors to typed errors. |
| mdl/executor/cmd_businessevents.go | Convert business events CRUD/show/describe errors to typed errors. |
| mdl/executor/cmd_associations.go | Convert association CRUD/show/describe errors to typed errors. |
| mdl/executor/cmd_agenteditor_models.go | Convert agent editor model show/describe errors to typed errors. |
| mdl/executor/cmd_agenteditor_mcpservices.go | Convert agent editor MCP service show/describe errors to typed errors. |
| mdl/executor/cmd_agenteditor_kbs.go | Convert agent editor KB show/describe errors to typed errors. |
| mdl/executor/cmd_agenteditor_agents.go | Convert agent editor agent show/describe errors to typed errors. |
| mdl/errors/errors_test.go | Add contract tests for new typed error behaviors. |
| mdl/errors/errors.go | Introduce new typed error definitions and constructors. |
| mdl/ast/ast_rest.go | gofmt/alignment only. |
| mdl/ast/ast_query.go | gofmt/alignment only. |
| mdl/ast/ast_microflow.go | gofmt/alignment only. |
| mdl/ast/ast_entity.go | gofmt/alignment only. |
| cmd/mxcli/docker/detect.go | Comment formatting only. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Introduce mdl/errors/ package with 6 structured error types: NotConnectedError, NotFoundError, AlreadyExistsError, UnsupportedError, ValidationError, BackendError. Migrate all ~1,084 fmt.Errorf calls across 79 executor files to typed errors. Enables programmatic error classification via errors.Is/errors.As for future dispatch registry, LSP integration, and API backend support. All existing consumers (CLI, TUI, LSP, diaglog) use .Error() only and remain fully compatible. ErrExit sentinel re-exported from executor package for backward compatibility.
626af7d to
caed015
Compare
AI Code ReviewWhat Looks Good:
Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
- Fix errors.go doc: clarify errors.As for classification, errors.Is for sentinels - Preserve context in NotFound messages for parameter/return type validation - Include full message in navigation profile NotFound error - Use ValidationError for version parse failures instead of BackendError - Include 'unsupported' prefix in container type UnsupportedError message
AI Code ReviewWhat Looks Good
RecommendationApprove. This is a well-executed, scoped refactor that significantly improves error handling for programmatic consumption while maintaining full backward compatibility. The typed error system will enable better error handling for consumers (LSP, TUI, API backends) without breaking existing consumers that only use Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
ReviewOverall: well-structured error system with a mechanical but correct migration across 79 files. CI is green, error messages are preserved, and the test coverage on the error types themselves is thorough. This is solid infrastructure that #224 builds on. What I like
Concerns
Minor
VerdictApprove. This should land before #224 (which depends on it). Concerns (1) and (2) are cleanup; (3)–(5) are suggestions for future iterations. No blockers. |
Summary
mdl/errors/package with 6 structured error types (NotConnectedError,NotFoundError,AlreadyExistsError,UnsupportedError,ValidationError,BackendError) plusErrExitsentinelfmt.Errorfcalls across 79 executor files to typed errors, enabling programmatic error classification viaerrors.Is/errors.Asfmt.Errorfcalls intentionally preserved (non-standard%wwrapping patterns)Motivation
The executor currently uses ad-hoc
fmt.Errorfstrings for all errors — no structure, no classification. This makes it impossible for consumers (LSP, TUI, API backends) to programmatically distinguish "not connected" from "entity not found" from "permission denied."Typed errors enable:
.mprv3 resilience:BackendErrorwraps I/O failures with operation context, decoupling error semantics from storage formatError Types
NotConnectedErrornot connected to a projectNotFoundErrorentity not found: MyModule.MyEntityAlreadyExistsErrorentity already exists: MyModule.MyEntityUnsupportedErrorunsupported attribute type: BinaryValidationErrorinvalid entity nameBackendErrorfailed to write entity: disk fullTesting
errors.Is/errors.Ascontract tests inmdl/errors/errors_test.gomake build✅,make test✅,make lint✅Notes
go fmton 12 files with pre-existing formatting issues (unrelated to typed errors)executor.ErrExitis re-exported from the new package for backward compatibility.Error()only and remain fully compatible