{"record":{"id":"53a0a30d50915310","repo":"Tencent/WeKnora","slug":"marshal-credentials-w","errorCode":null,"errorMessage":"marshal credentials: %w","messagePattern":"marshal credentials: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/datasource/connector/ima/types.go","lineNumber":63,"sourceCode":"\turl := strings.TrimSpace(c.BaseURL)\n\tif url == \"\" {\n\t\treturn DefaultBaseURL\n\t}\n\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 }`.","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/datasource/connector/ima/types.go#L45-L81","documentation":"Fires in parseIMAConfig when json.Marshal cannot serialize the datasource's Credentials map into JSON. With map credentials this is practically unreachable, so it signals a genuinely malformed credential value rather than user error.","triggerScenarios":"Thrown at internal/datasource/connector/ima/types.go:63 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect config.Credentials for unsupported or corrupted values","Log the underlying marshal error to identify the offending credential key","If credentials come from a store, validate them before passing to parseIMAConfig"],"exampleFix":null,"handlingStrategy":"try-catch","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"}