{"record":{"id":"b78620be4d9bff9a","repo":"Tencent/WeKnora","slug":"parse-ima-credentials-w","errorCode":null,"errorMessage":"parse ima credentials: %w","messagePattern":"parse ima credentials: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/datasource/connector/ima/types.go","lineNumber":67,"sourceCode":"\tif !strings.Contains(url, \"://\") {\n\t\turl = \"https://\" + url\n\t}\n\treturn strings.TrimRight(url, \"/\")\n}\n\n// parseIMAConfig extracts and validates IMA-specific configuration.\n// Uses JSON marshal/unmarshal roundtrip so extra fields are ignored gracefully.\nfunc parseIMAConfig(config *types.DataSourceConfig) (*Config, error) {\n\tif config == nil {\n\t\treturn nil, fmt.Errorf(\"%w: config is nil\", datasource.ErrInvalidConfig)\n\t}\n\tcredBytes, err := json.Marshal(config.Credentials)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"marshal credentials: %w\", err)\n\t}\n\tvar cfg Config\n\tif err := json.Unmarshal(credBytes, &cfg); err != nil {\n\t\treturn nil, fmt.Errorf(\"parse ima credentials: %w\", err)\n\t}\n\tif strings.TrimSpace(cfg.ClientID) == \"\" {\n\t\treturn nil, fmt.Errorf(\"%w: client_id is required\", datasource.ErrInvalidCredentials)\n\t}\n\tif strings.TrimSpace(cfg.APIKey) == \"\" {\n\t\treturn nil, fmt.Errorf(\"%w: api_key is required\", datasource.ErrInvalidCredentials)\n\t}\n\tif err := datasource.ValidateConnectorBaseURL(cfg.GetBaseURL()); err != nil {\n\t\treturn nil, err\n\t}\n\treturn &cfg, nil\n}\n\n// apiEnvelope is the uniform IMA response wrapper: `{ code, msg, data }`.\n// A non-zero code is a business-level error and MUST be surfaced to the user.\n//\n// Some published IMA references spell the same envelope `{ retcode, errmsg }`.\n// Accepting both costs nothing and avoids the failure mode where a mismatch","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/datasource/connector/ima/types.go#L49-L85","documentation":"Fires in parseIMAConfig when the JSON roundtrip unmarshal of the credentials into the IMA Config struct fails, meaning the credential JSON does not match the expected IMA schema (wrong types or shape for client_id/api_key fields).","triggerScenarios":"Thrown at internal/datasource/connector/ima/types.go:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify credentials contain client_id and api_key as strings","Remove or correct fields with mismatched JSON types","Extra unknown fields are safe to leave; only typed fields must match"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}