{"record":{"id":"173743c28ab173ce","repo":"owasp-amass/amass","slug":"addassetsbulk-status-s-error-s","errorCode":null,"errorMessage":"addAssetsBulk: status=%s error=%s","messagePattern":"addAssetsBulk: status=(.+?) error=(.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/api/client/v1/client.go","lineNumber":292,"sourceCode":"\tsessionID := token.String()\n\tbody, _ := json.Marshal(BulkAddAssetsRequest{Items: items})\n\tu := fmt.Sprintf(\"%s/sessions/%s/assets/%s:bulk\", c.base, sessionID, atype)\n\tresp, err := amasshttp.RequestWebPage(ctx, c.httpClient, &amasshttp.Request{\n\t\tURL:    u,\n\t\tBody:   string(body),\n\t\tMethod: http.MethodPost,\n\t\tHeader: amasshttp.Header{\"Content-Type\": []string{\"application/json\"}},\n\t})\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tmsg, err := readJSONError(resp.Body)\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"addAssetsBulk: status=%s\", resp.Status)\n\t\t}\n\t\treturn 0, fmt.Errorf(\"addAssetsBulk: status=%s error=%s\", resp.Status, msg)\n\t}\n\n\tvar out BulkAddAssetsResponse\n\tif err := json.Unmarshal([]byte(resp.Body), &out); err != nil {\n\t\treturn 0, err\n\t}\n\treturn int(out.Stored), nil\n}\n\n// Subscribe to receive a stream of log messages from the server.\nfunc (c *Client) Subscribe(ctx context.Context, token uuid.UUID) (<-chan string, error) {\n\tu, err := url.Parse(c.base)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tswitch u.Scheme {\n\tcase \"http\":","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/engine/api/client/v1/client.go#L274-L310","documentation":"CreateAssetsBulk's informative failure variant: the server returned non-200 with a parseable JSON error body, so the client surfaces the status plus the server's error message. The bulk insert failed as a whole per server semantics.","triggerScenarios":"Calling CreateAssetsBulk when the server explicitly rejects the batch — invalid token (401), unsupported asset type on :bulk path (404), validation or storage failure (400/500) — with a JSON error envelope.","commonSituations":"Server-side schema validation rejecting one asset shape, hitting an older server without the bulk endpoint, or expired session tokens in long-running workers.","solutions":["Read the error=%s portion for the server's specific rejection reason.","Fix the offending asset data per the server message.","Re-authenticate and refresh the session token if the status was 401.","Confirm the deployed server supports the :bulk endpoint; otherwise use per-asset CreateAsset.","Retry transient 5xx failures."],"exampleFix":"// before\n_, err := client.CreateAssetsBulk(ctx, token, atype, assets)\n// after\n_, err := client.CreateAssetsBulk(ctx, token, atype, assets)\nif err != nil {\n    if strings.Contains(err.Error(), \"status=401\") { token = reauth(ctx); return retry() }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if token == uuid.Nil { return errors.New(\"session token not initialized\") }\nfor _, a := range assets { if _, err := a.JSON(); err != nil { return err } }","typeGuard":"func isAuthFailure(err error) bool { return err != nil && strings.Contains(err.Error(), \"status=401\") }","tryCatchPattern":"count, err := client.CreateAssetsBulk(ctx, token, atype, assets)\nif err != nil {\n    if isAuthFailure(err) { token = reauth(ctx); return client.CreateAssetsBulk(ctx, token, atype, assets) }\n    return fmt.Errorf(\"bulk add rejected: %w\", err)\n}","preventionTips":["Parse and log the server's error= message for root cause.","Re-authenticate automatically on 401.","Verify server support for the :bulk endpoint before using it.","Validate all asset payloads client-side before batching."],"tags":["http","api-client","server-error"],"backgroundTag":"http-error-response","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}