{"record":{"id":"ff7ec1bc7f3419e3","repo":"owasp-amass/amass","slug":"addcredentials-the-credentials-argument-is-invali","errorCode":null,"errorMessage":"AddCredentials: The Credentials argument is invalid","messagePattern":"AddCredentials: The Credentials argument is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/oam_i2y/ini.go","lineNumber":332,"sourceCode":"\tdefer c.Unlock()\n\n\tkey := strings.TrimSpace(source)\n\tif key == \"\" {\n\t\treturn nil\n\t}\n\tif c.datasrcConfigs == nil {\n\t\tc.datasrcConfigs = make(map[string]*DataSourceConfig)\n\t}\n\tif _, found := c.datasrcConfigs[key]; !found {\n\t\tc.datasrcConfigs[key] = &DataSourceConfig{Name: key}\n\t}\n\treturn c.datasrcConfigs[key]\n}\n\n// AddCredentials adds the Credentials provided to the configuration.\nfunc (dsc *DataSourceConfig) AddCredentials(cred *Credentials) error {\n\tif cred == nil || cred.Name == \"\" {\n\t\treturn fmt.Errorf(\"AddCredentials: The Credentials argument is invalid\")\n\t}\n\n\tif dsc.creds == nil {\n\t\tdsc.creds = make(map[string]*Credentials)\n\t}\n\n\tdsc.creds[cred.Name] = cred\n\treturn nil\n}\n\n// AddDomain appends the domain name provided in the parameter to the list in the configuration.\nfunc (c *Config) AddDomain(domain string) {\n\tc.Lock()\n\tdefer c.Unlock()\n\n\t// Check that the domain string is not empty\n\td := strings.TrimSpace(domain)\n\tif d == \"\" {","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/cmd/oam_i2y/ini.go#L314-L350","documentation":"AddCredentials on DataSourceConfig adds a *Credentials entry keyed by name. If the argument is nil or has an empty Name, the credentials cannot be keyed or used, so this error is returned without mutating state.","triggerScenarios":"Calling dsc.AddCredentials(nil), or with &Credentials{Name: \"\"} (name never set, or set after construction and lost).","commonSituations":"Building credentials programmatically from config files where the username/name key is missing; zero-value Credentials structs passed in; refactored code that no longer populates Name before calling AddCredentials.","solutions":["Ensure the Credentials value is non-nil and Name is populated before calling AddCredentials.","If loading credentials from a config file, check that the name/username key exists and is non-empty.","Add a constructor (NewCredentials(name, pass)) that rejects empty names at creation time."],"exampleFix":"// before\ncred := &Credentials{Pass: \"secret\"}\ndsc.AddCredentials(cred) // error: Name empty\n// after\nif cred.Name == \"\" {\n    cred.Name = cfg.GetString(\"datasource.username\")\n}\nerr := dsc.AddCredentials(cred)","handlingStrategy":"validation","validationCode":"if cred == nil || cred.Name == \"\" {\n    return errors.New(\"cannot add credentials: nil or missing Name\")\n}\nreturn dsc.AddCredentials(cred)","typeGuard":"func validCredentials(c *Credentials) bool {\n    return c != nil && c.Name != \"\"\n}","tryCatchPattern":"if err := dsc.AddCredentials(cred); err != nil {\n    if strings.Contains(err.Error(), \"The Credentials argument is invalid\") {\n        return fmt.Errorf(\"credential for %s missing name: %w\", dsc.Name(), err)\n    }\n}","preventionTips":["Construct credentials via a constructor that requires a non-empty name.","Never pass zero-value Credentials structs.","When loading from config, fail fast on empty username keys."],"tags":["validation","credentials","go"],"backgroundTag":"null-argument","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"}