gofr-dev/gofr · error

invalid Azure configuration: share name is required

Error message

invalid Azure configuration: share name is required

What it means

azure.New validates its Azure Files configuration before building a client. If the Config's ShareName is empty, it returns the sentinel errInvalidConfig — "invalid Azure configuration: share name is required". All Azure Files operations target a share, so an empty share name makes the filesystem unusable and the library fails fast at construction instead of erroring on every later call.

Source

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

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)
}

View on GitHub (pinned to 187eb24962)

Solutions

  1. Set ShareName on the Config passed to azure.New (e.g. cfg.ShareName = "my-share" or via the environment variable the app maps from).
  2. Verify the environment variable feeding ShareName is actually set in the deployment (kubectl describe pod / .env file).
  3. Ensure azure.New receives a non-nil *Config — nil config also fails validation.
  4. Add a startup-time validation in your own code to fail deployment early with a clear message.

Example fix

// before
fs := azure.New(nil)
// after
cfg := &Config{ShareName: os.Getenv("AZURE_SHARE"), AccountName: acc, AccountKey: key}
if cfg.ShareName == "" {
    log.Fatal("AZURE_SHARE env var must be set")
}
fs := azure.New(cfg)
Defensive patterns

Strategy: validation

Validate before calling

cfg := azure.New(nil) // never — validate first
func validateAzureConfig(cfg *azure.Config) error {
    if cfg == nil || cfg.ShareName == "" {
        return errors.New("azure share name must be configured")
    }
    return nil
}

Type guard

func azureConfigValid(cfg *azure.Config) bool {
    return cfg != nil && cfg.ShareName != "" && cfg.AccountName != "" && cfg.AccountKey != ""
}

Try / catch

fs := azure.New(cfg)
if errors.Is(fs, errInvalidConfig) /* or err != nil check at New */ {
    log.Fatal("azure share name missing — check AZURE share config")
}

Prevention

When it happens

Trigger: Calling azure.New(nil-config or config) where cfg.ShareName == "" — e.g. azure.New(nil), a FileSystem config struct built without setting ShareName, or ShareName sourced from an unset/empty environment variable.

Common situations: Missing AZURE_FILES_SHARE_NAME env var in deployment; config struct fields populated in the wrong order; copy-pasted config where the share key was renamed; tests constructing bare &file.FileSystem{} without ShareName.

Related errors


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