{"record":{"id":"fd36089d5e669b03","repo":"owasp-amass/amass","slug":"addcredentials-the-accountname-argument-is-invali","errorCode":null,"errorMessage":"AddCredentials: The accountName argument is invalid","messagePattern":"AddCredentials: The accountName argument is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/datasrcs.go","lineNumber":60,"sourceCode":"\tkey := strings.ToLower(strings.TrimSpace(source))\n\tif key == \"\" || c.DataSrcConfigs == nil {\n\t\treturn nil\n\t}\n\n\tvar dsc *DataSource\n\tfor _, src := range c.DataSrcConfigs.Datasources {\n\t\tif strings.ToLower(src.Name) == key {\n\t\t\tdsc = src\n\t\t\tbreak\n\t\t}\n\t}\n\treturn dsc\n}\n\n// AddCredentials adds the Credentials provided to the configuration.\nfunc (ds *DataSource) AddCredentials(accountName string, cred *Credentials) error {\n\tif accountName == \"\" || ds == nil {\n\t\treturn fmt.Errorf(\"AddCredentials: The accountName argument is invalid\")\n\t}\n\n\tif ds.Creds == nil {\n\t\tds.Creds = make(map[string]*Credentials)\n\t}\n\n\tds.Creds[accountName] = cred\n\treturn nil\n}\n\n// GetCredentials returns the first set of Credentials associated with the given DataSource name.\nfunc (dsc *DataSourceConfig) GetCredentials(dsName string) *Credentials {\n\tif dsc == nil || dsc.Datasources == nil {\n\t\treturn nil\n\t}\n\n\tfor _, src := range dsc.Datasources {\n\t\tif src.Name == dsName && src.Creds != nil {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/config/datasrcs.go#L42-L78","documentation":"DataSource.AddCredentials adds a *Credentials entry under an accountName key, but rejects the call when accountName is the empty string or the receiver ds is nil. The error indicates a programming mistake by the caller rather than a config file problem: credentials were passed without a usable account identifier.","triggerScenarios":"Calling ds.AddCredentials(\"\", cred) with an empty account name, or calling the method on a nil *DataSource obtained from a failed lookup (e.g. GetDataSource returning nil).","commonSituations":"Programmatic config construction where the account name comes from a variable that is unset/empty; forgetting to check that a data source lookup succeeded before adding credentials; refactors that dropped the name assignment.","solutions":["Pass a non-empty accountName: ds.AddCredentials(\"account1\", cred).","Ensure the *DataSource receiver is non-nil before calling AddCredentials (check the lookup/constructor result).","If the name comes from user input or env, validate it is non-empty before the call.","Log or return which data source failed so the empty name's origin is traceable."],"exampleFix":"// before\nds.AddCredentials(account, cred) // account may be \"\"\n// after\nif account == \"\" {\n    return fmt.Errorf(\"account name required for datasource %s\", dsName)\n}\nds.AddCredentials(account, cred)","handlingStrategy":"type-guard","validationCode":"if ds == nil {\n    return fmt.Errorf(\"datasource not initialized\")\n}\nif accountName == \"\" {\n    return fmt.Errorf(\"accountName must be non-empty\")\n}","typeGuard":"func addable(ds *config.DataSource, accountName string) bool {\n    return ds != nil && accountName != \"\"\n}","tryCatchPattern":"if err := ds.AddCredentials(name, cred); err != nil {\n    if strings.Contains(err.Error(), \"accountName argument is invalid\") {\n        // log which datasource/credential pair failed\n    }\n    return err\n}","preventionTips":["Always check data-source lookups/constructors for nil before use","Validate account names at their source (input, env, config)","Wrap AddCredentials in a helper that enforces non-empty names"],"tags":["api-misuse","validation","credentials","nil-check"],"backgroundTag":"invalid-argument-value","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}