Skip to content

Conversation

@mkedjour
Copy link
Contributor

@mkedjour mkedjour commented Nov 5, 2025

Description

  • Removed the use of errutil.Err() and replaced with with fmt.Errorf()
  • Moved all the packages that we don't want to make external from pkg to internal/pkg (log, db, grpc, ...)
  • Added contextual logging interceptor, it will log the information related to the current gRPC request (full method, etc.).
  • Added a custom Gorm logger that uses logrus and our logging config.

Type of Change

  • Bugfix
  • New Feature
  • Breaking Change
  • Refactor
  • Documentation
  • Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

Signed-off-by: Mohamed Tahar KEDJOUR <mkedjour@cisco.com>
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@jadiaconu jadiaconu requested a review from Copilot November 7, 2025 16:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the error handling and logging infrastructure by moving the log package from pkg/log to internal/pkg/log and removing the custom errutil.Err() wrapper in favor of standard Go error handling with errors.New() and fmt.Errorf().

  • Migrated logging package from public to internal with enhanced context-aware logging capabilities
  • Replaced custom error wrapper errutil.Err() with standard Go error handling patterns
  • Added contextual logger interceptor for gRPC to enrich logs with request metadata

Reviewed Changes

Copilot reviewed 36 out of 38 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/log/log.go Removed old public log package
internal/pkg/log/log.go New internal log package with context enrichment support
internal/pkg/db/logger.go New logrus logger adapter for GORM database operations
internal/pkg/db/context.go Renamed type from context to dbContext and integrated new logger
internal/pkg/shutdown.go New utility function for graceful shutdown with context
internal/pkg/errutil/error.go Removed Err() function, keeping only ErrInfo()
pkg/oidc/provider.go Updated to use standard error wrapping and internal log package
pkg/oidc/parser.go Replaced errutil.Err() with errors.New() and fmt.Errorf()
internal/node/grpc/interceptors/contextual_logger.go New interceptor to enrich context with gRPC metadata for logging
internal/node/grpc/interceptors/contextual_logger_test.go Test coverage for contextual logger interceptor
internal/node/grpc/interceptors/errors.go Updated to use context-aware logging
internal/node/vc_service.go Replaced direct log calls with context-aware log.FromContext(ctx)
internal/node/id_service.go Updated logging to use context-aware approach
internal/node/id_generator.go Updated logging to use context-aware approach
internal/node/grpc/issuer.go Updated logging to use context-aware approach
internal/core/issuer/verification/service.go Updated to use context-aware logging and standard error handling
internal/core/vc/postgres/repository.go Replaced errutil.Err() with fmt.Errorf()
internal/core/issuer/postgres/repository.go Replaced errutil.Err() with fmt.Errorf()
internal/core/id/postgres/repository.go Replaced errutil.Err() with fmt.Errorf()
internal/issuer/badge/service.go Replaced custom error wrapper with standard Go error handling
internal/issuer/badge/mcp/discover.go Updated error handling and fixed typo in comment
internal/pkg/httputil/data.go Updated import path for log package
internal/pkg/grpcserver/server.go Updated import path for pkg package
internal/pkg/convertutil/common.go Updated import path for log package
internal/pkg/cmd/config.go Updated to use log.WithError() instead of logrus.Fields
internal/pkg/cache/cache.go Updated import path for log package
internal/issuer/vault/data/repository.go Removed unnecessary import alias
internal/issuer/vault/data/filesystem/repository.go Removed unnecessary import alias
cmd/node/main.go Updated imports, improved variable naming, and added contextual logger interceptor
cmd/node/configuration.go Added IsDev() helper method
cmd/issuer/commands/issuer/register.go Fixed error message (removed invalid error wrapping)
cmd/issuer/commands/badge/issue/*.go Removed unnecessary import aliases
.gitignore Added /.run/ directory to ignored files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

err,
"failed to discover mcp server",
)
return nil, fmt.Errorf("failed to discover mcp tools: %w", err)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent capitalization in error messages. Line 58 uses "failed to discover mcp tools" while line 66 uses "failed to discover MCP resources". Both should use consistent capitalization for "MCP" (uppercase acronym).

Suggested change
return nil, fmt.Errorf("failed to discover mcp tools: %w", err)
return nil, fmt.Errorf("failed to discover MCP tools: %w", err)

Copilot uses AI. Check for mistakes.
Comment on lines 48 to 50
defer func(mcpClient *client.Client) {
_ = mcpClient.Close()
}(mcpClient)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defer function unnecessarily captures mcpClient as a parameter when it's already in scope. The simpler form defer mcpClient.Close() would work, or if error handling is needed, use defer func() { _ = mcpClient.Close() }() without the parameter.

Suggested change
defer func(mcpClient *client.Client) {
_ = mcpClient.Close()
}(mcpClient)
defer mcpClient.Close()

Copilot uses AI. Check for mistakes.
Comment on lines 46 to 67
// Info : Configure log level
func Info(args ...any) {
logrus.Info(args...)
}

// Debug : Configure log level
func Debug(args ...any) {
logrus.Debug(args...)
}

// Fatal : Configure log level
func Fatal(args ...any) {
logrus.Fatal(args...)
}

// Error : Configure log level
func Error(args ...any) {
logrus.Error(args...)
}

func Warn(args ...any) {
logrus.Warn(args...)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function comments "Configure log level" are incorrect for these logging functions. They should describe what each function does (e.g., "Info logs an informational message", "Debug logs a debug message", etc.)

Copilot uses AI. Check for mistakes.
}

func (l *logrusLogger) Warn(ctx context.Context, msg string, data ...any) {
log.FromContext(ctx).Infof(msg, data...)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Warn method is calling log.FromContext(ctx).Infof() instead of log.FromContext(ctx).Warnf(). This should log at the warning level, not info level.

Suggested change
log.FromContext(ctx).Infof(msg, data...)
log.FromContext(ctx).Warnf(msg, data...)

Copilot uses AI. Check for mistakes.
nCtx := ctx

if stored, ok := ctx.Value(contextLogFieldsKey{}).(logrus.Fields); ok {
maps.Copy(stored, fields)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maps.Copy function copies from the second argument to the first argument, so this should be maps.Copy(fields, stored) to preserve existing context fields and add new ones. Currently, this overwrites the new fields with the old ones, which is the opposite of the intended behavior.

Copilot uses AI. Check for mistakes.
Signed-off-by: Mohamed Tahar KEDJOUR <mkedjour@cisco.com>
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.

2 participants