Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom flag validation #303

Merged
merged 7 commits into from
Dec 10, 2024
Merged

Custom flag validation #303

merged 7 commits into from
Dec 10, 2024

Conversation

mkysel
Copy link
Collaborator

@mkysel mkysel commented Dec 4, 2024

Summary by CodeRabbit

  • New Features

    • Introduced command-line options for various functionalities, including key generation, node registration, and health updates.
    • Added validation for server configuration options to enhance error handling and user feedback.
  • Bug Fixes

    • Improved error handling for option parsing to provide clearer messages for help and parsing errors.
  • Chores

    • Simplified the structure of command-line options by consolidating related fields, improving organization and reducing complexity.
    • Updated database initialization logic to conditionally create instances based on enabled features.
    • Enhanced server initialization logic for clearer service management.

Copy link

coderabbitai bot commented Dec 4, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces significant modifications across several files, primarily focusing on restructuring command-line options and enhancing server configuration validation. The globalOptions struct is removed in favor of a new config.GlobalOptions struct, simplifying the CLI struct. The main function in cmd/replication/main.go now includes improved error handling and validation for server options. Additionally, several database connection options have been made optional in pkg/config/options.go, and a new validation function for server options is introduced in pkg/config/validation.go. Overall, these changes aim to streamline configuration management and improve code clarity.

Changes

File Path Change Summary
cmd/cli/main.go Removed globalOptions struct; integrated fields into config.GlobalOptions; updated parseOptions function.
cmd/replication/main.go Enhanced error handling for option parsing; added validation step for server options; updated database initialization logic.
pkg/config/options.go Removed required:"true" tags from several fields in DbOptions and PayerOptions, making them optional.
pkg/config/validation.go Introduced ValidateServerOptions function to validate server configuration options, providing detailed error reporting.
pkg/server/server.go Removed writerDB field from ReplicationServer; updated service initialization logic; added startAPIServer function.
pkg/config/cliOptions.go Introduced several new structs for command-line options, including GlobalOptions and various operation-specific options.

Possibly related PRs

Suggested reviewers

  • richardhuaaa
  • neekolas

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 62b954d and 77c0599.

📒 Files selected for processing (1)
  • cmd/cli/main.go (2 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
pkg/config/validation.go (1)

14-33: Refactor: Consolidate Repetitive Validation Checks

The validation for DB.WriterConnectionString is repeated for Replication, Sync, and Indexer. Consider consolidating these checks to reduce code duplication.

Apply this refactor to simplify the validation:

if options.Replication.Enable || options.Sync.Enable || options.Indexer.Enable {
	if options.DB.WriterConnectionString == "" {
		return errors.New("DB.WriterConnectionString is required")
	}
}
cmd/cli/options.go (2)

14-17: Consider Marking Mandatory Fields as Required

If AdminPrivateKey and NodeId are mandatory for UpdateHealthOptions, consider adding required:"true" to enforce this at the command-line parsing level.


19-23: Consider Marking Mandatory Fields as Required

In UpdateAddressOptions, adding required:"true" to PrivateKey, NodeId, and Address will ensure these fields are provided when the command is used.

cmd/cli/main.go (2)

Line range hint 46-85: Consider improving error message consistency and function structure.

  1. Error message capitalization is inconsistent:

    • Some use "Could not..."
    • Others use "could not..."
  2. The function handles multiple responsibilities and could benefit from decomposition.

Consider:

  1. Standardizing error message format:
-		return nil, fmt.Errorf("Could not parse options: %s", err)
+		return nil, fmt.Errorf("could not parse options: %s", err)
  1. Breaking down the function into smaller, focused functions:
func addCommands(parser *flags.Parser, options *CLI) error {
    // Add all commands
}

func validateParserResults(parser *flags.Parser) error {
    // Handle parsing results
}

func parseOptions(args []string) (*CLI, error) {
    options := initializeOptions()
    parser := flags.NewParser(&options.GlobalOptions, flags.Default)
    
    if err := addCommands(parser, options); err != nil {
        return nil, err
    }
    
    if err := validateParserResults(parser, args); err != nil {
        return nil, err
    }
    
    return options, nil
}

Line range hint 1-248: Overall structure looks good with room for future improvements.

The refactoring of the CLI options structure is well-executed. Future improvements could include:

  1. Breaking down the large command handler functions (e.g., registerNode, updateHealth) into smaller, more focused functions
  2. Adding validation for the HTTP addresses in registerNode and updateAddress
  3. Consider introducing interfaces for better testing and dependency injection

Consider introducing a Registry interface to abstract the blockchain operations:

type Registry interface {
    AddNode(ctx context.Context, owner string, key *ecdsa.PublicKey, addr string) error
    UpdateHealth(ctx context.Context, nodeID string, health bool) error
    // ... other methods
}

This would:

  • Make the code more testable
  • Allow for different implementations (e.g., for testing or different backends)
  • Simplify the command handlers
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 906ba3f and 45ee6d7.

📒 Files selected for processing (6)
  • cmd/cli/main.go (2 hunks)
  • cmd/cli/options.go (1 hunks)
  • cmd/replication/main.go (4 hunks)
  • pkg/config/options.go (3 hunks)
  • pkg/config/validation.go (1 hunks)
  • pkg/server/server.go (4 hunks)
🔇 Additional comments (14)
pkg/server/server.go (4)

85-95: Conditional Initialization of 'Registrant' Service

The Registrant service is now initialized only when Replication or Sync is enabled, which optimizes resource usage by avoiding unnecessary initialization.


99-107: Initialization of validationService for Indexer

The validationService is correctly initialized using mlsvalidate.NewMlsValidationService, ensuring messages are validated properly when the Indexer is enabled.


122-137: Refactor: Simplify API Server Start Logic

Extracting the API server startup into the startAPIServer function improves code readability and separation of concerns.


138-152: Conditional Initialization of SyncServer

The SyncServer is initialized only when Sync is enabled, which is appropriate and conserves resources.

pkg/config/validation.go (1)

8-12: Consistent Validation of Payer Private Key

The check for options.Payer.PrivateKey when Payer is enabled is appropriate to prevent misconfiguration.

cmd/cli/options.go (2)

25-27: Approved: Required Annotation for Private Key

The GetPubKeyOptions struct correctly marks PrivateKey as required, ensuring the necessary information is supplied.


29-34: Approved: Required Fields in RegisterNodeOptions

All necessary fields in RegisterNodeOptions are appropriately marked as required, which will enforce proper usage of the command.

cmd/replication/main.go (3)

40-44: Validation of Server Options

Calling config.ValidateServerOptions(options) ensures that the server will not start with invalid configurations, preventing runtime errors due to misconfiguration.


66-77: Conditional Database Initialization

The database is now initialized only if Replication, Sync, or Indexer are enabled, optimizing resource usage.


68-77: Error Handling with Database Initialization

Proper error handling is in place for database initialization failures, logging the error and terminating the application if necessary.

pkg/config/options.go (2)

23-26: Removal of required:"true" Tags from DbOptions

The required:"true" tags have been removed from DbOptions fields. Since validation is now explicitly handled in ValidateServerOptions, this change centralizes validation logic.


42-42: Removal of required:"true" Tag from PayerOptions.PrivateKey

Removing the required:"true" tag is acceptable because the new validation function ensures that PrivateKey is provided when the Payer is enabled.

cmd/cli/main.go (2)

38-44: LGTM: Option initialization looks correct.

The variable declarations properly align with the CLI struct fields and use the new local option types.


18-25: Verify the new option types and potential name conflicts.

The embedding of GlobalOptions and removal of the config. prefix suggests these types have been moved locally. Please ensure:

  1. All option types (GetPubKeyOptions, GenerateKeyOptions, etc.) are properly defined in the new location
  2. No field name conflicts exist between the embedded GlobalOptions and the CLI struct
✅ Verification successful

All option types are properly defined and no conflicts found

The verification shows:

  • All option types are properly defined in cmd/cli/options.go
  • GlobalOptions only contains Contracts and Log fields which don't conflict with any fields in the CLI struct
  • The removal of the config. prefix is valid as these types are now locally defined
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the option types are defined in the new location
fd -e go -x grep -l "type.*Options struct" {}

# Check for potential field name conflicts
ast-grep --pattern 'type GlobalOptions struct {
  $$$
}'

Length of output: 456


Script:

#!/bin/bash
# Check the definition of all option types in cmd/cli/options.go
cat cmd/cli/options.go

# Check for any field name conflicts between CLI struct and GlobalOptions
ast-grep --pattern 'type CLI struct {
  $$$
}'

Length of output: 2110

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
pkg/config/validation.go (4)

8-11: Add function documentation.

Please add a documentation comment that describes the function's purpose, parameters, and return values. This will help other developers understand how to use this validation function.

+// ValidateServerOptions validates the provided ServerOptions configuration.
+// It checks for required fields and valid values across different option sections.
+// Returns an error if any validation fails, with a detailed message of all validation errors.
 func ValidateServerOptions(options ServerOptions) error {

40-44: Standardize flag naming in error messages.

For consistency with other error messages, use kebab-case format for flag names.

 if options.Payer.Enable {
     if options.Payer.PrivateKey == "" {
-        missingSet["--payer.PrivateKey"] = struct{}{}
+        missingSet["--payer.private-key"] = struct{}{}
     }
 }

67-87: Consider using structured validation errors.

The current error handling concatenates strings, which makes it harder for callers to programmatically handle specific validation failures. Consider using a custom validation error type.

+type ValidationError struct {
+    MissingFields []string
+    CustomErrors  []string
+}
+
+func (v ValidationError) Error() string {
+    var parts []string
+    if len(v.MissingFields) > 0 {
+        parts = append(parts, "Missing required arguments: " + strings.Join(v.MissingFields, ", "))
+    }
+    if len(v.CustomErrors) > 0 {
+        parts = append(parts, strings.Join(v.CustomErrors, "; "))
+    }
+    return strings.Join(parts, "; ")
+}

 if len(missingSet) > 0 || len(customSet) > 0 {
-    var errs []string
+    ve := ValidationError{}
     if len(missingSet) > 0 {
-        var errorMessages []string
-        errorMessages = append(errorMessages, "Missing required arguments:")
         for err := range missingSet {
-            errorMessages = append(errorMessages, err)
+            ve.MissingFields = append(ve.MissingFields, err)
         }
-        errs = append(errs, strings.Join(errorMessages, ", "))
     }
     if len(customSet) > 0 {
         for err := range customSet {
-            errs = append(errs, err)
+            ve.CustomErrors = append(ve.CustomErrors, err)
         }
     }
-    return errors.New(strings.Join(errs, "; "))
+    return ve
 }

8-87: Consider architectural improvements and add unit tests.

  1. The validation function handles multiple concerns. Consider splitting it into smaller, focused validators for each section (Contracts, Payer, etc.).
  2. Add unit tests to verify validation behavior for various scenarios:
    • All valid options
    • Missing required fields
    • Invalid values
    • Different combinations of enabled features

Would you like me to help with:

  1. Restructuring the validation into smaller, focused validators?
  2. Creating a comprehensive test suite?
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 45ee6d7 and 4c5ce4a.

📒 Files selected for processing (1)
  • pkg/config/validation.go (1 hunks)

@mkysel mkysel force-pushed the mkysel/custom-flag-validation branch from 4c5ce4a to b90e1e7 Compare December 4, 2024 19:54
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
cmd/cli/main.go (1)

38-44: Consider enhancing the command registration logic.

While the option type changes look good, there are opportunities to improve the command registration:

  1. The repeated command registration pattern could be refactored to reduce duplication
  2. Error messages could be more descriptive by including the specific validation failure
  3. Consider adding explicit validation for required fields

Here's a suggested approach to reduce duplication:

type commandDef struct {
    name        string
    description string
    options     interface{}
}

func (cli *CLI) registerCommands(parser *flags.Parser) error {
    commands := []commandDef{
        {"generate-key", "Generate a public/private keypair", &cli.GenerateKey},
        {"register-node", "Register a node", &cli.RegisterNode},
        // ... other commands
    }
    
    for _, cmd := range commands {
        if _, err := parser.AddCommand(cmd.name, cmd.description, "", cmd.options); err != nil {
            return fmt.Errorf("failed to add command %s: %w", cmd.name, err)
        }
    }
    return nil
}
pkg/server/server.go (2)

99-106: Consider validating MlsValidation options before use.

While the validation service initialization looks correct, it might be beneficial to validate the MlsValidation options before using them to create the service.

Consider adding validation in ValidateServerOptions:

func ValidateServerOptions(options ServerOptions) error {
    // existing validation...
+   if options.Indexer.Enable {
+       if err := validateMlsOptions(options.MlsValidation); err != nil {
+           return fmt.Errorf("invalid MLS validation options: %w", err)
+       }
+   }
    return nil
}

Line range hint 156-217: Consider refactoring service registration for better maintainability.

While the function is well-structured, consider these improvements:

  1. Split the service registration closure into separate functions for each service
  2. Avoid redeclaring the err variable in the closure

Here's a suggested refactoring:

func startAPIServer(...) error {
    var err error

-   serviceRegistrationFunc := func(grpcServer *grpc.Server) error {
-       if options.Replication.Enable {
-           replicationService, err := message.NewReplicationApiService(...)
-           if err != nil {
-               return err
-           }
-           message_api.RegisterReplicationApiServer(grpcServer, replicationService)
-           log.Info("Replication service enabled")
-       }
-       if options.Payer.Enable {
-           // ... payer service initialization
-       }
-       return nil
-   }
+   serviceRegistrationFunc := createServiceRegistrationFunc(ctx, log, options, s, writerDB, blockchainPublisher)

    s.apiServer, err = api.NewAPIServer(...)
    return err
}

+func createServiceRegistrationFunc(...) func(*grpc.Server) error {
+   return func(grpcServer *grpc.Server) error {
+       if err := registerReplicationService(...); err != nil {
+           return err
+       }
+       if err := registerPayerService(...); err != nil {
+           return err
+       }
+       return nil
+   }
+}
+
+func registerReplicationService(...) error {
+   if !options.Replication.Enable {
+       return nil
+   }
+   // Replication service initialization
+}
+
+func registerPayerService(...) error {
+   if !options.Payer.Enable {
+       return nil
+   }
+   // Payer service initialization
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4c5ce4a and 735afac.

📒 Files selected for processing (6)
  • cmd/cli/main.go (2 hunks)
  • cmd/cli/options.go (1 hunks)
  • cmd/replication/main.go (4 hunks)
  • pkg/config/options.go (3 hunks)
  • pkg/config/validation.go (1 hunks)
  • pkg/server/server.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • cmd/replication/main.go
  • pkg/config/validation.go
  • cmd/cli/options.go
  • pkg/config/options.go
🔇 Additional comments (5)
cmd/cli/main.go (1)

18-25: LGTM! Good structural improvements to the CLI type.

The changes improve code organization by:

  1. Embedding GlobalOptions directly
  2. Moving option types locally for better encapsulation

Let's verify the option types are properly defined:

✅ Verification successful

CLI refactoring verified successfully

The verification confirms:

  1. All command-specific option types are properly defined in cmd/cli/options.go
  2. The remaining config package references are valid and intentional, specifically for ContractsOptions and LogOptions which are well-defined in pkg/config/options.go
  3. No other unexpected config package references exist in the CLI code
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify option types are properly defined in the new file
# and there are no lingering references to the old config package

# Check for option type definitions
rg "type.*Options struct" cmd/cli/

# Verify no lingering config package references
rg "config\.[A-Za-z]+Options" cmd/cli/

Length of output: 640


Script:

#!/bin/bash
# Let's verify if the config package references are valid imports
# and check the structure of these options

# Check imports in options.go
rg "^import.*config" cmd/cli/options.go -A 5

# Check the structure of ContractsOptions and LogOptions in config package
fd "config" --type f --exec rg "type (Contracts|Log)Options struct" {} \;

Length of output: 360


Script:

#!/bin/bash
# Let's try a different approach to find these option types
# by searching in the pkg/config directory specifically

# Check for the options types in pkg/config
rg "type (Contracts|Log)Options struct" pkg/config/ -A 3

# Also verify there are no other config package references
# in the CLI code that might need attention
rg "config\." cmd/cli/ -l

Length of output: 1302

pkg/server/server.go (4)

6-6: LGTM: Import added for new validation service.


122-136: LGTM: Clean API server initialization.

The conditional initialization and error handling look good. The logging provides clear feedback about the server state.


138-151: LGTM: Clean sync server initialization.

The conditional initialization, dependency injection, and error handling are well implemented.


85-95: Verify feature flag combinations.

The registrant initialization is now conditional on either Replication or Sync being enabled, which is logically correct. However, let's verify all possible feature flag combinations are handled properly.

✅ Verification successful

Let me analyze the usage of these feature flags to verify their combinations.


Let me try a different approach to check the configuration structure.


Based on the results from the first search, I can now generate a final response as we have enough information about how these feature flags are used together.

Feature flag combinations are properly handled

The codebase shows consistent and correct handling of the Replication and Sync feature flags:

  • Registrant is correctly initialized when either flag is enabled
  • Each feature has proper validation in config/validation.go ensuring required dependencies
  • The features are independently handled in their respective initialization blocks
  • Database connections are properly set up when either feature is enabled
  • All combinations maintain proper dependency chain (registrant -> sync/replication services)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all places where these feature flags are used together
rg -A 5 "options\.(Replication|Sync)\.Enable"

Length of output: 2168


Script:

#!/bin/bash
# Let's check the configuration structure and defaults
ast-grep --pattern 'type Options struct {
  $$$
}'

Length of output: 52


Script:

#!/bin/bash
# Search for the Options struct definition using ripgrep
rg -A 20 "type Options struct"

Length of output: 32

@mkysel mkysel marked this pull request as ready for review December 4, 2024 20:37
@mkysel mkysel requested a review from a team as a code owner December 4, 2024 20:37
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
pkg/config/cliOptions.go (2)

8-10: Add documentation for empty option structs

The purpose of these empty structs is not immediately clear. Consider adding documentation to explain their intended use and why they don't require any fields.

+// GenerateKeyOptions defines options for key generation operations.
 type GenerateKeyOptions struct{}

+// GetAllNodesOptions defines options for retrieving all nodes.
 type GetAllNodesOptions struct{}

1-32: Consider adding constants for validation patterns

To improve maintainability and ensure consistency across the codebase, consider extracting the validation patterns into constants.

 package config

+const (
+	// Validation patterns for CLI options
+	PrivateKeyPattern    = "^0x[a-fA-F0-9]{64}$"
+	PublicKeyPattern     = "^0x[a-fA-F0-9]{128}$"
+	AddressPattern       = "^https?://[\\w.-]+(:\\d+)?$"
+	BlockchainAddrPattern = "^0x[a-fA-F0-9]{40}$"
+)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 735afac and ecd5a6b.

📒 Files selected for processing (2)
  • cmd/cli/main.go (2 hunks)
  • pkg/config/cliOptions.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/cli/main.go
🔇 Additional comments (1)
pkg/config/cliOptions.go (1)

3-6: Verify the existence of referenced option types

The structure looks well-organized with proper namespace separation. However, let's verify the referenced types exist.

✅ Verification successful

Referenced types are properly defined

Both ContractsOptions and LogOptions are well-defined in pkg/config/options.go with appropriate fields and configuration tags.

  • ContractsOptions is defined with blockchain-related configuration options
  • LogOptions is defined with logging-related configuration options
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if ContractsOptions and LogOptions are defined
# Expected: Find definitions of these types in the codebase

echo "Checking for ContractsOptions..."
ast-grep --pattern 'type ContractsOptions struct { $$$ }'

echo "Checking for LogOptions..."
ast-grep --pattern 'type LogOptions struct { $$$ }'

Length of output: 2430

Comment on lines +66 to +67
var dbInstance *sql.DB
if options.Replication.Enable || options.Sync.Enable || options.Indexer.Enable {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it makes sense to use a singleton pattern for the DB, and just instantiate it wherever it is needed, rather than trying to comprehensively enumerate all the cases here.

Or: Just instantiate the DB if the DB params are specified, and don't instantiate if it's not, and throw an error if a DB is used somewhere when it hasn't been instantiated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will give it some thought tomorrow!

@mkysel mkysel enabled auto-merge (squash) December 10, 2024 16:12
@mkysel mkysel merged commit 896e00c into main Dec 10, 2024
8 of 9 checks passed
@mkysel mkysel deleted the mkysel/custom-flag-validation branch December 10, 2024 16:20
This was referenced Mar 6, 2025
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