Commit Graph

3 Commits

Author SHA1 Message Date
56c6045e3b Use ngx_log_error! macro and fix formatting
- Switched from ngx_log_error_core() to ngx_log_error! macro
- Changed error_log level from debug to info (cleaner output)
- Formatting cleanup across all modules (cargo fmt)
- Removed trailing newlines and fixed indentation

Logging now properly uses nginx's macro system for better
integration with nginx's log handling.
2025-11-15 17:16:55 -08:00
86b79c0a85 Implement structured logging with ngx_log_error_core
Logging now uses nginx's native error log with proper levels:
- ERROR (level 3): Configuration/query/template failures
- WARN (level 4): Missing parameters
- INFO (level 6): Request processing, template resolution
- DEBUG (level 7): Detailed tracing

Log Format: [sqlite-serve:module] message

Example output:
- [info] [sqlite-serve:handler] Processing request for /books
- [info] [sqlite-serve:template] Resolved template: ./server_root/books/catalog.hbs
- [info] [sqlite-serve:params] Resolved 1 parameters
- [notice] [sqlite-serve:success] Rendered catalog.hbs with 1 params

Specialized logging functions:
- log_config_error(): Invalid configuration
- log_query_error(): SQL errors with query shown
- log_template_error(): Template failures with path
- log_param_error(): Parameter resolution issues
- log_request_success(): Successful processing info
- log_template_loading(): Template discovery

Uses ngx_log_error_core() C API directly for dynamic messages.

Test Coverage: 59 tests
Configuration: error_log set to debug level for visibility
2025-11-15 17:05:09 -08:00
032a105b3f Achieve handler correctness by construction (9-line handler)
Handler: 52 lines -> 9 lines (Ghost of Departed Proofs)

New Pattern: ValidConfigToken
- Proof token that config is non-empty
- Can only be created if validation passes
- Handler accepts token, not raw config
- Types guarantee correctness

Handler Logic (9 lines):
1. Get config
2. Try to create ValidConfigToken (proof of validity)
3. If proof exists: process_request(request, proof)
4. If no proof: return NGX_OK (not configured)

New Modules:
- handler_types.rs (168 lines): ValidConfigToken + process_request
  - ValidConfigToken: Proof that config is valid
  - process_request(): Uses proof to guarantee safety
  - execute_with_processor(): DI setup isolated

Correctness by Construction:
✓ Handler cannot process invalid config (token required)
✓ Token can only exist if config is valid
✓ Type system enforces the proof
✓ No error handling needed for proven facts
✓ Handler is obviously correct by inspection

Benefits:
- Handler is trivially correct (no tests needed)
- All complexity moved to tested modules
- Clear separation: validation vs execution
- Types carry proofs (Ghost of Departed Proofs)
- Single responsibility: handler just gates on proof

Test Coverage: 58 tests (+4 token validation tests)
Handler Size: 9 lines (was 170)
lib.rs: 257 lines (was 423)

The handler is now so simple it's obviously correct!
2025-11-15 16:55:57 -08:00