-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Bug Report: Silent Integer Parsing Failures in GoFr Container
Describe the bug
Several configuration values in pkg/gofr/container/container.go are parsed using strconv.Atoi where the returned error is explicitly ignored (assigned to _). If a user provides an invalid value (e.g., a non-numeric string or a value with units like "500ms"), the configuration silently defaults to 0 without any log or warning.
This affects:
- MQTT_PORT (Line 182)
- PARTITION_SIZE (Line 331)
- PUBSUB_OFFSET (Line 339)
- KAFKA_BATCH_SIZE (Line 340)
- KAFKA_BATCH_BYTES (Line 341)
- KAFKA_BATCH_TIMEOUT (Line 342)
For example, setting KAFKA_BATCH_TIMEOUT="500ms" results in a timeout of 0 (likely misinterpreted as 0ms or immediate timeout), whereas the intention was 500 milliseconds.
To Reproduce
Steps to reproduce the behavior:
-
Set an invalid integer value for one of the affected configurations in your
.envfile or environment variables:export MQTT_PORT="invalid_port" export KAFKA_BATCH_TIMEOUT="500ms"```
-
Initialize a GoFr application that uses these configurations (e.g., utilizing MQTT or Kafka PubSub).
-
The application starts without any error logs, but the port will be set to
0and the timeout to0.
Expected behavior
The application should validate the integer configuration. If parsing fails, it should log a warning to inform the user that the provided value is invalid and state that it is falling back to the default value.
Screenshots
N/A
Environments (please complete the following information):
- OS:OS: macOS
- gofr version: development
- go version: 1.25
More description
I have identified the issue in pkg/gofr/container/container.go and can implement a helper function getIntConfig that handles the strconv.Atoi error by logging a warning and returning the default value.