encore
encore copied to clipboard
Bug: initService() is not called, leading to nil pointer dereference
The initService() function is defined but does not appear to be executed. As a result, when trying to use emailSender, a nil pointer dereference error occurs. Additionally, the expected log message ("Initializing SSO service...") does not appear in the output.
type ssoService struct {
emailSender *EmailSender
}
type SsoService interface {
// Methods...
}
func initService() (SsoService, error) {
rlog.Info("Initializing SSO service....")
return &EmailSender{
SMTPHost: os.Getenv("SMTP_HOST"),
SMTPPort: 587,
Sender: os.Getenv("SMTP_SENDER"),
Password: os.Getenv("SMTP_PASSWORD"),
}, nil
}
Expect to see the log output "Initializing SSO service...", but it does not appear. Attempt to use emailSender, which leads to a nil pointer dereference error. Expected Behavior
The log message "Initializing SSO service..." should appear. emailSender should be properly initialized and not nil. Actual Behavior
No log output from initService(). emailSender is nil, causing a runtime panic (nil pointer dereference).
The name of the function is init<NameOfServiceStruct>. So in your case it needs to be called initSsoService. The struct itself must also be annotated with //encore:service.