Commit e1d01c2
feat: comprehensive architecture improvements for error handling, testing, and configuration (#133)
* feat: comprehensive architecture improvements for error handling and testing
This PR implements a major architectural improvement initiative focused on:
## Structured Error Codes System
- Tokenizer: Updated all errors to use structured error codes (E1001-E1005)
- Parser: Updated 50+ errors across 8 files to use structured errors (E2001-E2012)
- All errors now include: error codes, location info, helpful hints, and doc links
## CLI Enhancement
- Added `Code` field to JSON output for validation and parse errors
- Errors now propagate structured error codes to CLI output
## LSP Integration
- Updated `createDiagnosticFromError` to extract and display error codes
- VS Code Problems panel now shows structured error codes
## Unified Configuration Package
- Created `pkg/config/` with Config struct, file/env loaders, LSP integration
- Test coverage: 78.6%
## Testing Improvements
- Added `pkg/lsp/handler_test.go` (660 lines)
- Added `pkg/lsp/server_ratelimit_test.go` (400 lines)
- Added `pkg/lsp/handler_errorcode_test.go`
- Added `pkg/sql/security/scanner_bench_test.go` (16 benchmarks)
- Added `pkg/lsp/handler_bench_test.go` (21+ benchmarks)
## Documentation Updates
- Updated CLI_GUIDE.md, API_REFERENCE.md, ERROR_CODES.md
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* fix: address PR #133 review feedback
- Fix SA4010 lint error in LoadFromFiles() by renaming unused 'errs' to
'triedPaths' and including tried paths in the error message for better
debugging
- Add documentation comment to mergeInto() explaining the known limitation
where boolean fields only merge when true, preventing explicit false
override via environment variables
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* docs: update issue reference to #134 in config mergeInto comment
* fix: remove unused error type check in fuzz test (SA4006)
* fix: use *bool pointers for config boolean fields (closes #134)
This fixes the boolean merging logic issue where boolean fields could
not be explicitly set to false via environment variables to override
config file values.
Changes:
- Change all boolean config fields from `bool` to `*bool` pointers:
- Format.UppercaseKeywords, Format.Compact
- Validation.StrictMode, Validation.Recursive
- Output.Verbose
- Analyze.Security, Analyze.Performance, Analyze.Complexity, Analyze.All
- Server.MetricsEnabled
- Add helper functions in config.go:
- Bool(v bool) *bool - creates a pointer to a bool
- BoolValue(p *bool) bool - returns false if nil
- BoolValueOr(p *bool, defaultVal bool) bool - returns default if nil
- Update mergeInto() to use != nil checks instead of truthy checks,
allowing explicit false values to override defaults
- Update LoadFromEnvironment() to use Bool() helper
- Update ToLSPSettings/FromLSPSettings to use BoolValue()/Bool()
- Update all tests to use BoolValue() for assertions
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* test: add integration tests for error propagation chain
Add comprehensive integration tests that verify:
- Error codes propagate correctly from tokenizer to parser
- Error code extraction works with IsCode() helper
- Error location information is preserved through parsing pipeline
Tests cover various SQL error scenarios:
- Unterminated string literals (tokenizer error)
- Incomplete SQL statements
- Missing table names (INSERT INTO VALUES)
- Unexpected token usage (SELECT FROM users)
- Multiline error location tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Ajit Pratap Singh <[email protected]>
Co-authored-by: Claude <[email protected]>1 parent 139ad0a commit e1d01c2
File tree
34 files changed
+5672
-134
lines changed- cmd/gosqlx/internal/output
- docs
- examples/sql-validator
- pkg
- config
- errors
- lsp
- sql
- parser
- security
- tokenizer
34 files changed
+5672
-134
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| 102 | + | |
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| |||
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
| 136 | + | |
133 | 137 | | |
134 | 138 | | |
135 | 139 | | |
136 | | - | |
| 140 | + | |
| 141 | + | |
137 | 142 | | |
138 | 143 | | |
139 | 144 | | |
| |||
219 | 224 | | |
220 | 225 | | |
221 | 226 | | |
| 227 | + | |
222 | 228 | | |
223 | 229 | | |
224 | 230 | | |
| |||
229 | 235 | | |
230 | 236 | | |
231 | 237 | | |
232 | | - | |
| 238 | + | |
| 239 | + | |
233 | 240 | | |
234 | 241 | | |
235 | 242 | | |
| |||
267 | 274 | | |
268 | 275 | | |
269 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
270 | 305 | | |
271 | 306 | | |
272 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
199 | 229 | | |
200 | 230 | | |
201 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
270 | 319 | | |
271 | 320 | | |
272 | 321 | | |
| |||
0 commit comments