{"record":{"id":"f129048ad9b97485","repo":"ipfs/kubo","slug":"expected-a-file-argument","errorCode":null,"errorMessage":"expected a file argument","messagePattern":"expected a file argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/add.go","lineNumber":694,"sourceCode":"\t\t\t\t}\n\n\t\t\t\tif err := res.Emit(&addEvent); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif err := <-errCh; err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tadded++\n\t\t}\n\n\t\tif addit.Err() != nil {\n\t\t\treturn addit.Err()\n\t\t}\n\n\t\tif added == 0 {\n\t\t\treturn fmt.Errorf(\"expected a file argument\")\n\t\t}\n\n\t\thasRoot := lastRootCid != path.ImmutablePath{}\n\n\t\tif fastProvideDAG && hasRoot {\n\t\t\t// DAG walk includes the root CID (DFS pre-order emits it\n\t\t\t// first), so a separate root provide is not needed.\n\t\t\tcmdenv.ExecuteFastProvideDAG(\n\t\t\t\treq.Context,\n\t\t\t\tipfsNode.Context(),\n\t\t\t\t[]cid.Cid{lastRootCid.RootCid()},\n\t\t\t\tipfsNode.ProvidingStrategy,\n\t\t\t\tipfsNode.Blockstore,\n\t\t\t\tipfsNode.Provider,\n\t\t\t\tfastProvideWait,\n\t\t\t\tuint(cfg.Provide.BloomFPRate.WithDefault(config.DefaultProvideBloomFPRate)),\n\t\t\t\t0, // block count unknown here; bloom chain auto-grows\n\t\t\t)","sourceCodeStart":676,"sourceCodeEnd":712,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/add.go#L676-L712","documentation":"After iterating all input entries, the add command checks that at least one entry was actually processed (added > 0). If the iterator yielded nothing usable, there is nothing to add, so it errors. This is the guard for an empty or nonexistent input set.","triggerScenarios":"Run `ipfs add` with stdin left empty (`ipfs add < /dev/null` or `echo -n | ipfs add -`); pass a file argument that resolves to zero entries; the added counter never increments because it.Next() returned no entries.","commonSituations":"Piping empty stdin into add in shell pipelines; a variable holding an empty path; CI scripts where the file to add was not produced by a prior step; reading from a FIFO that closed immediately.","solutions":["Pass a real file or directory argument: ipfs add ./myfile","Check the upstream pipeline actually emits bytes before piping into `ipfs add -`","Verify the file exists and is non-empty before invoking add in scripts"],"exampleFix":"// before\necho -n | ipfs add -\n// after\ntest -s \"$FILE\" && ipfs add \"$FILE\" || echo \"no input\" >&2","handlingStrategy":"validation","validationCode":"// verify input before ipfs add\nif [ ! -s \"$FILE\" ]; then echo \"empty or missing input: $FILE\" >&2; exit 1; fi\nipfs add \"$FILE\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check files are non-empty before piping into `ipfs add -`","Fail the pipeline early when an upstream step produces no output","In CI, assert the artifact to be added exists before the add step"],"tags":["cli","add","empty-input","stdin"],"backgroundTag":"empty-input-argument","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"}