{"record":{"id":"bb81056e1550c34d","repo":"gofr-dev/gofr","slug":"azure-config-is-nil","errorCode":null,"errorMessage":"azure config is nil","messagePattern":"azure config is nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/azure/storage_adapter.go","lineNumber":22,"sourceCode":"\t\"bytes\"\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"mime\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/directory\"\n\tazfile \"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file\"\n\t\"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share\"\n\t\"gofr.dev/pkg/gofr/datasource/file\"\n)\n\nvar (\n\t// Storage adapter errors.\n\terrAzureConfigNil            = errors.New(\"azure config is nil\")\n\terrAzureClientNotInitialized = errors.New(\"azure client or share is not initialized\")\n\terrEmptyObjectName           = errors.New(\"object name is empty\")\n\terrInvalidOffset             = errors.New(\"invalid offset: must be >= 0\")\n\terrEmptySourceOrDest         = errors.New(\"source and destination names cannot be empty\")\n\terrSameSourceOrDest          = errors.New(\"source and destination are the same\")\n\terrFailedToCreateReader      = errors.New(\"failed to create reader\")\n\terrFailedToCreateRangeReader = errors.New(\"failed to create range reader\")\n\terrObjectNotFound            = errors.New(\"object not found\")\n\terrFailedToGetProperties     = errors.New(\"failed to get properties\")\n\terrFailedToDeleteObject      = errors.New(\"failed to delete object\")\n\terrFailedToCopyObject        = errors.New(\"failed to copy object\")\n\terrFailedToListObjects       = errors.New(\"failed to list objects\")\n\terrFailedToListDirectory     = errors.New(\"failed to list directory\")\n\terrWriterAlreadyClosed       = errors.New(\"writer already closed\")\n\terrInvalidWhence             = errors.New(\"invalid whence\")\n\terrNegativeOffset            = errors.New(\"negative offset\")\n\terrShareNameEmpty            = errors.New(\"share name cannot be empty\")\n)","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/azure/storage_adapter.go#L4-L40","documentation":"storage_adapter.Connect(ctx, cfg) requires a non-nil *Config; if cfg is nil it returns the sentinel errAzureConfigNil — \"azure config is nil\". The adapter cannot build the azfile service client or share client without connection parameters, so Connect fails immediately rather than returning an adapter whose client is unusable. This is distinct from the fs.go errInvalidConfig family: it guards the Connect lifecycle, not New.","triggerScenarios":"Calling Connect(ctx, nil) on the Azure storage adapter — e.g. wiring the FileSystem without loading config first, a framework hook passing a nil config interface, or a struct field of pointer type left as its zero value.","commonSituations":"App startup where datasource config loading is skipped or fails silently; test scaffolding calling Connect without config; refactors changing config from value to pointer type leaving nil defaults; conditional config loading branches that never ran.","solutions":["Pass a fully populated *Config (ShareName, AccountName, AccountKey, endpoints) to Connect.","Fix config loading order — load and validate configuration before the datasource Connect lifecycle runs.","If using the higher-level azure.New, ensure its Config is built before FileSystem.Connect is invoked.","Add a nil check/panic-early in your wiring code so the misconfiguration surfaces at boot with clear context."],"exampleFix":"// before\nvar cfg *Config\nfs.Connect(ctx, cfg) // panics into errAzureConfigNil\n// after\ncfg := &Config{ShareName: \"files\", AccountName: acc, AccountKey: key}\nif err := fs.Connect(ctx, cfg); err != nil {\n    log.Fatalf(\"azure files connect failed: %v\", err)\n}","handlingStrategy":"validation","validationCode":"if cfg == nil {\n    return errors.New(\"azure config must be loaded before Connect\")\n}","typeGuard":"func canConnect(cfg *azure.Config) bool {\n    return cfg != nil && cfg.ShareName != \"\" && cfg.AccountName != \"\" && cfg.AccountKey != \"\"\n}","tryCatchPattern":"if err := adapter.Connect(ctx, cfg); err != nil {\n    if strings.Contains(err.Error(), \"config is nil\") {\n        log.Fatal(\"azure storage adapter: config was nil at Connect — check config loading order\")\n    }\n    return err\n}","preventionTips":["Load and validate datasource config before running any Connect lifecycle.","Avoid zero-value pointer configs; construct explicitly at startup.","Write a startup integration test that performs Connect with production-shaped config."],"tags":["azure","configuration","nil-config","azure-files"],"backgroundTag":"missing-config-field","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}