Skip to content

fix: console.error/warn calls in server (59 occurrences) should go through structured logger#856

Open
3m1n3nc3 wants to merge 1018 commits into
bakeronchain:mainfrom
3m1n3nc3:fix/console-error-warn-calls-in-server-59-occurrences-should-go-through-structured-logger
Open

fix: console.error/warn calls in server (59 occurrences) should go through structured logger#856
3m1n3nc3 wants to merge 1018 commits into
bakeronchain:mainfrom
3m1n3nc3:fix/console-error-warn-calls-in-server-59-occurrences-should-go-through-structured-logger

Conversation

@3m1n3nc3

Copy link
Copy Markdown
Contributor

Summary

This PR replaces raw console.error and console.warn usage across the server codebase with the shared structured logger so error reporting goes through a consistent JSON log path.

What changed

  • added a shared server logger with scoped structured output
  • sanitized logged Error objects so production logs omit stack traces
  • migrated server runtime logging from raw console.error and console.warn to the logger
  • migrated server TypeScript maintenance scripts to the same logger
  • added tests covering logger sanitization behavior
  • added an ESLint rule to ban bare console.error in server source and scripts

Why

Raw console calls bypass the server’s structured logging path and make production debugging harder. They also increase the chance of leaking stack traces or inconsistent error payloads. This change centralizes error serialization and makes server-side logging safer and easier to query.

Validation

  • confirmed there are no remaining raw console.error or console.warn calls under server source or server TS scripts
  • added focused logger tests for production-safe error sanitization
  • checked editor diagnostics for touched files

Type of Change

  • Bug fix
  • New feature
  • Smart contract change
  • Documentation
  • Breaking change
  • Other (please describe)

Checklist

Screenshots (if applicable)

Testing

Added focused coverage for the new logging behavior in server/src/tests/logger.test.ts

Additional Notes

Jenola344 and others added 30 commits April 24, 2026 03:20
- Extracted allowedOrigins to separate config file for better testability
- Added integration tests for CORS preflight and origin verification
- Fixed typescript compilation errors in credentials controller and auth middleware
- Verified full compliance with CORS acceptance criteria

Closes bakeronchain#607
- Created user_profiles table migration with unique display_name constraint
- Added GET /api/profiles/:address public endpoint
- Added PUT /api/profiles/me authenticated upsert endpoint
- Added UserProfileSchema for robust input validation
- Implemented strict HTML sanitization for user bios
- Created comprehensive integration tests for profile operations

Closes bakeronchain#625
- Add Flag button on comments with reason input
- Create flagged_content table with reporter tracking and audit log
- Admin moderation queue at /api/admin/moderation
- Admin actions: delete content, dismiss flag, warn user
- Auto-hide content with 3+ pending flags
- Email admin on new flag with review link
- Filter hidden comments from public view
…ones

- Add generateRequestId() to utils/errors — surfaces a short ref ID
  in the ErrorBoundary and ErrorState so users can quote it to support
- ErrorBoundary: generate request ID on catch, replace alert() with a
  mailto: "Contact Support" link pre-filled with error details
- ErrorState: add requestId + showContactSupport props; render ref ID
  and contact-support mailto link for unexpected errors
- lib/api: attach X-Request-ID header to every fetch; include the ref
  in thrown errors so it propagates up to UI error messages
- utils/errors + util/error: rewrite all fallback messages to describe
  what happened AND what the user can do next (no bare "Something went
  wrong" or "Request failed")
- types/errors: add requestId field to AppError / createAppError
- Treasury: swap inline red-text error for ErrorState with retry
- Courses: use hook refetch() for retry instead of full page reload
- Leaderboard: extract fetchLeaderboard to useCallback so retry works
  without a hard reload; propagate HTTP status into error message
- Admin: make all inline panel error strings action-oriented
- useProposals: improve readJson fallback and castVote not-connected
  messages to tell the user what to do, not just what failed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ance token

Contract:
- Add DelegateChanged event (emitted when delegation target changes)
- Add DelegateRemoved event (emitted on undelegate / self-delegate)
- Emit both events in delegate() and undelegate() respectively
- get_voting_power() was already implemented and accounts for
  delegated weight; no logic change needed there

Backend:
- stellar-contract.service: add getGovernanceVotingPower() that
  simulates get_voting_power() (balance + received delegations) and
  getGovernanceDelegation() that simulates get_delegate()
- governance.controller: add getDelegation endpoint returning
  delegatee, is_delegating, own_balance, delegated_to_me,
  voting_power for any address
- governance.controller: switch getVotingPower and castVote to use
  getGovernanceVotingPower() so delegated weight is counted in votes
- governance.routes: register GET /governance/delegation/:address
- migration 009: delegation_events table to index on-chain
  DelegateChanged / DelegateRemoved events

Frontend:
- governance_token.ts stub: add get_voting_power, get_delegate,
  delegate, undelegate stubs so build succeeds before client gen
- useDelegation hook: queries /api/governance/delegation/:address
  for delegation state; delegateTo() and undelegate() mutations drive
  the contract client (signAndSend pattern from useGovernance)
- Dao.tsx: delegation panel with own/delegated/effective power
  breakdown, current delegatee display + Undelegate button, and
  address-input form to set a new delegate
- Add sanitize-html to all user text endpoints
- Apply XSS protection to proposals, comments, milestone evidence, and course descriptions
- Implement Zod max-length validators with proper error messages
- Ensure oversized inputs return 400 instead of 500
- Add comprehensive test suite for sanitization
- Configure allowed HTML tags for rich text formatting
- Strip all HTML from titles and rejection reasons for security

Security improvements:
- Comments: Strip all HTML tags (existing)
- Proposals: Sanitize titles and descriptions
- Milestone evidence: Sanitize evidence descriptions
- Courses: Sanitize titles and descriptions
- Admin rejections: Sanitize rejection reasons

All endpoints now consistently handle XSS protection and input validation.
…8-566

feat: request tracing, escrow timeout automation, and allowlist storage fix
…ommunity-bounty-boar

Fix bakeronchain#666: feat: add community bounty board page
- Fix optionalTrimmedString function to properly handle maxLength parameter
- Update requiredString function to accept optional maxLength
- Fix chaining .max() on optional types causing TS errors
- Export app from index.ts for test imports
- Remove problematic test file to fix CI/CD

All Zod schemas now properly compile with correct type safety.
- Remove max length from Zod comment validation to allow manual validation
- Update vite-plugin-node-polyfills to v0.27.0 for vite 8 compatibility
- Fixes comments test expecting specific error message for 2000+ char limit
- Resolves npm ERESOLVE conflicts blocking CI/CD pipeline

Note: GlobalSearch.tsx ESLint issue not found - may be in different branch
- Add comprehensive environment variable setup for tests
- Mock all external services (Pinata, email, escrow-timeout, request-context)
- Add request logger middleware to test app for requestId generation
- Fix test expectations to match actual contract service call signatures
- Update Pinata service to handle test environments gracefully
- All 25 governance tests now passing

Security features remain fully functional with proper test coverage.
@Anuoluwapo25

Copy link
Copy Markdown
Contributor

try force async.... pull from upsteam @3m1n3nc3

…n-calls-in-server-59-occurrences-should-go-through-structured-logger
@3m1n3nc3

Copy link
Copy Markdown
Contributor Author

try force async.... pull from upsteam @3m1n3nc3

I've done that

@Anuoluwapo25

Copy link
Copy Markdown
Contributor

i still can't merge and i can't fix from my end...you can ask AI for assistance

Anuoluwapo25 and others added 6 commits April 29, 2026 21:56
feat: complete i18n translations and localization for French language…
…prep

feat: prepare smart contracts for formal security audit
…-cache

feat: Add Redis RPC cache layer to reduce Stellar RPC calls per page load
…n-calls-in-server-59-occurrences-should-go-through-structured-logger
@3m1n3nc3

Copy link
Copy Markdown
Contributor Author

i still can't merge and i can't fix from my end...you can ask AI for assistance

I've resolved the remaining conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: console.error/warn calls in server (59 occurrences) should go through structured logger