Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit e9852ef

Browse files
committed
fix: throw error on missing input to add/addAll
Throws an error with a more descriptive error message. The error messages over http are not descriptive due to node-fetch/node-fetch#753 Fixes #3788
1 parent df04d7e commit e9852ef

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/interface-ipfs-core/src/add.js

+10
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ module.exports = (factory, options) => {
233233
await expect(ipfs.add(nonValid)).to.eventually.be.rejected()
234234
})
235235

236+
it('should fail when passed undefined input', async () => {
237+
// @ts-expect-error undefined is non valid
238+
await expect(ipfs.add(undefined)).to.eventually.be.rejected()
239+
})
240+
241+
it('should fail when passed null input', async () => {
242+
// @ts-expect-error null is non valid
243+
await expect(ipfs.add(null)).to.eventually.be.rejected()
244+
})
245+
236246
it('should wrap content in a directory', async () => {
237247
const data = { path: 'testfile.txt', content: fixtures.smallFile.data }
238248

packages/ipfs-core-utils/src/files/normalise-input/normalise-input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const {
2828
// eslint-disable-next-line complexity
2929
module.exports = async function * normaliseInput (input, normaliseContent) {
3030
if (input === null || input === undefined) {
31-
return
31+
throw errCode(new Error(`Unexpected input: ${input}`), 'ERR_UNEXPECTED_INPUT')
3232
}
3333

3434
// String

0 commit comments

Comments
 (0)