gofr-dev/gofr · error

invalid Azure configuration: account name is required

Error message

invalid Azure configuration: account name is required

What it means

During azure.New, validation checks that Config.AccountName is non-empty and returns the sentinel errAccountNameRequired — "invalid Azure configuration: account name is required" — if it is blank. The account name identifies the storage account hosting the file share and is required to build the azfile service client, so the library refuses to construct the filesystem without it.

Source

Thrown at pkg/gofr/datasource/file/azure/fs.go:13

package azure

import (
	"context"
	"errors"
	"time"

	"gofr.dev/pkg/gofr/datasource/file"
)

var (
	errInvalidConfig       = errors.New("invalid Azure configuration: share name is required")
	errAccountNameRequired = errors.New("invalid Azure configuration: account name is required")
	errAccountKeyRequired  = errors.New("invalid Azure configuration: account key is required")
)

const defaultTimeout = 10 * time.Second

type azureFileSystem struct {
	*file.CommonFileSystem
}

// Config represents the Azure File Storage configuration.
type Config struct {
	AccountName string // Azure Storage Account name
	AccountKey  string // Azure Storage Account key
	ShareName   string // Azure File Share name
	Endpoint    string // Azure Storage endpoint (optional, defaults to core.windows.net)
}

// New creates and validates a new Azure File Storage file system.

View on GitHub (pinned to 187eb24962)

Solutions

  1. Set Config.AccountName to the Azure storage account name before calling azure.New.
  2. Verify the environment variable/secret feeding the account name resolves in the target environment.
  3. Check for typos between config struct keys and the source (yaml/env/json) keys.
  4. Log-or-assert non-empty account name at application startup for fail-fast behavior.

Example fix

// before
cfg := &Config{ShareName: "files", AccountKey: key} // AccountName missing
fs := azure.New(cfg)
// after
cfg := &Config{ShareName: "files", AccountName: os.Getenv("AZURE_ACCOUNT_NAME"), AccountKey: key}
fs := azure.New(cfg)
Defensive patterns

Strategy: validation

Validate before calling

if cfg.AccountName == "" {
    return errors.New("AZURE_ACCOUNT_NAME is required for azure files")
}

Type guard

func hasAccountName(cfg *azure.Config) bool {
    return cfg != nil && strings.TrimSpace(cfg.AccountName) != ""
}

Prevention

When it happens

Trigger: Calling azure.New with a Config whose AccountName == "": the env var for the storage account unset, a typo in the config key, or building the struct with only AccountKey and ShareName set.

Common situations: Deploying to an environment where AZURE_STORAGE_ACCOUNT_NAME was never injected; renaming config keys during refactor; multi-environment setups where staging config omits the account name; secrets manager returning empty values.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/944634ef00646f67. Report an issue: GitHub.