{"record":{"id":"71d0f913d872013e","repo":"ipfs/kubo","slug":"checkcidsize-getting-node-size-w","errorCode":null,"errorMessage":"CheckCIDSize: getting node size: %w","messagePattern":"CheckCIDSize: getting node size: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/cmdutils/utils.go","lineNumber":37,"sourceCode":"\tSoftBlockLimit  = 2 * 1024 * 1024 // https://specs.ipfs.tech/bitswap-protocol/#block-sizes\n\tMaxPinNameBytes = 255             // Maximum number of bytes allowed for a pin name\n)\n\nvar AllowBigBlockOption cmds.Option\n\nfunc init() {\n\tAllowBigBlockOption = cmds.BoolOption(AllowBigBlockOptionName, \"Disable block size check and allow creation of blocks bigger than 2MiB. WARNING: such blocks won't be transferable over the standard bitswap.\").WithDefault(false)\n}\n\nfunc CheckCIDSize(req *cmds.Request, c cid.Cid, dagAPI coreiface.APIDagService) error {\n\tn, err := dagAPI.Get(req.Context, c)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"CheckCIDSize: getting dag: %w\", err)\n\t}\n\n\tnodeSize, err := n.Size()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"CheckCIDSize: getting node size: %w\", err)\n\t}\n\n\treturn CheckBlockSize(req, nodeSize)\n}\n\nfunc CheckBlockSize(req *cmds.Request, size uint64) error {\n\tallowAnyBlockSize, _ := req.Options[AllowBigBlockOptionName].(bool)\n\tif allowAnyBlockSize {\n\t\treturn nil\n\t}\n\n\t// Block size is limited to SoftBlockLimit (2MiB) as defined in the bitswap spec.\n\t// https://specs.ipfs.tech/bitswap-protocol/#block-sizes\n\tif size > SoftBlockLimit {\n\t\treturn fmt.Errorf(\"produced block is over 2MiB: big blocks can't be exchanged with other peers. consider using UnixFS for automatic chunking of bigger files, or pass --allow-big-block to override\")\n\t}\n\treturn nil\n}","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/cmdutils/utils.go#L19-L55","documentation":"CheckCIDSize calls n.Size() on the fetched DAG node to obtain its byte size for the block-size check. Size() can fail for nodes whose size cannot be computed (e.g. raw/unsupported node types), and the failure is wrapped with this prefix. The block-size limit check itself then runs in CheckBlockSize.","triggerScenarios":"dag put / related commands where the fetched node's Size() errors — typically raw or unixfs nodes without length metadata, or a codec whose size computation is unsupported.","commonSituations":"Putting raw blocks whose size cannot be derived; custom codec nodes; corrupted nodes in the datastore.","solutions":["Inspect the wrapped error; unsupported node kinds are the usual cause","Prefer wrapping content in UnixFS so sizes are computable","If the node is raw, use its encoded length or skip the size check via --allow-big-block semantics where appropriate"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"n, err := dagAPI.Get(ctx, c)\nif err != nil {\n    return err\n}\nif _, err := n.Size(); err != nil {\n    return fmt.Errorf(\"node size unsupported: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := cmdutils.CheckCIDSize(req, c, dagAPI); err != nil {\n    if strings.Contains(err.Error(), \"getting node size\") {\n        // fall back to skipping the size check or use raw block length\n    }\n    return err\n}","preventionTips":["Prefer UnixFS-wrapped content whose sizes are always computable","Avoid custom/raw codecs in flows that must enforce block-size limits","Test with representative node types before production use"],"tags":["dag","blocksize","cid"],"backgroundTag":"node-size-unavailable","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}