{"record":{"id":"d30869b89104a490","repo":"larksuite/cli","slug":"create-http-client-w","errorCode":null,"errorMessage":"create HTTP client: %w","messagePattern":"create HTTP client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/identitydiag/diagnostics.go","lineNumber":386,"sourceCode":"\tresult, err := f.Credential.ResolveToken(ctx, credential.NewTokenSpec(core.AsBot, cfg.AppID))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif result == nil || result.Token == \"\" {\n\t\treturn nil, &credential.TokenUnavailableError{Type: credential.TokenTypeTAT}\n\t}\n\treturn result, nil\n}\n\ntype botInfo struct {\n\tOpenID  string\n\tAppName string\n}\n\nfunc fetchBotInfo(ctx context.Context, f *cmdutil.Factory, cfg *core.CliConfig, token *credential.TokenResult) (*botInfo, error) {\n\thttpClient, err := f.HttpClient()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create HTTP client: %w\", err)\n\t}\n\tctx = core.WithCredentialSource(ctx, token.Source)\n\tctx, cancel := context.WithTimeout(ctx, verifyTimeout)\n\tdefer cancel()\n\turl := strings.TrimRight(core.ResolveEndpoints(cfg.Brand).Open, \"/\") + \"/open-apis/bot/v3/info\"\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+token.Token)\n\n\tresp, err := httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, _ := io.ReadAll(resp.Body)","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/identitydiag/diagnostics.go#L368-L404","documentation":"This error wraps the failure to construct the CLI's shared HTTP client before fetching bot info from the Lark bot/v3/info endpoint. The Factory's HttpClient() builds a client from the resolved configuration (endpoints, timeouts, transport); if that construction fails, identity diagnostics cannot proceed. The %w wrap preserves the underlying cause (bad config, TLS setup failure, etc.) for errors.Is/As inspection.","triggerScenarios":"fetchBotInfo calls f.HttpClient() and it returns an error — reached via diagnoseBot or diagnoseExternalBot during identity diagnostics runs.","commonSituations":"Malformed proxy configuration in the environment (HTTP_PROXY/HTTPS_PROXY unparseable); invalid TLS/CA settings in CLI config; corrupted CliConfig values the transport builder rejects; custom transport factory misconfiguration.","solutions":["Inspect the wrapped cause (the part after 'create HTTP client:') for the exact construction failure.","Check proxy environment variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) for malformed URLs and fix or unset them.","Validate CLI config (TLS/CA cert paths, timeouts) that the HTTP client builder consumes.","Re-run the diagnostics command after fixing config to confirm bot auth works."],"exampleFix":"// before: bad proxy env breaks client construction\nHTTPS_PROXY=\"://not-a-url\" lark-cli doctor identity\n\n// after\nunset HTTPS_PROXY   # or set a valid URL\nHTTPS_PROXY=\"http://proxy.corp:8080\" lark-cli doctor identity","handlingStrategy":"validation","validationCode":"for _, v := range []string{\"HTTP_PROXY\", \"HTTPS_PROXY\", \"NO_PROXY\"} {\n    if u := os.Getenv(v); u != \"\" {\n        if _, err := url.Parse(u); err != nil {\n            return fmt.Errorf(\"invalid %s: %w\", v, err)\n        }\n    }\n}\n// also verify configured CA files exist and are readable before running diagnostics","typeGuard":null,"tryCatchPattern":"info, err := fetchBotInfo(ctx, f, cfg, token)\nif err != nil {\n    var wrap *fmt.wrapError\n    if errors.As(err, &wrap) && strings.HasPrefix(err.Error(), \"create HTTP client:\") {\n        return fmt.Errorf(\"check proxy/TLS config: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate proxy URLs in your environment before running CLI commands.","Keep CA bundle paths in CLI config pointing to existing files.","Run `lark-cli config check`/doctor-style commands after config changes.","Avoid hand-editing transport settings without testing client construction."],"tags":["http-client","configuration","diagnostics"],"backgroundTag":"http-client-init-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}