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

Commit

Permalink
fix: throw error on missing input to add/addAll
Browse files Browse the repository at this point in the history
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
  • Loading branch information
achingbrain committed Aug 17, 2021
1 parent df04d7e commit e9852ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/interface-ipfs-core/src/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ module.exports = (factory, options) => {
await expect(ipfs.add(nonValid)).to.eventually.be.rejected()
})

it('should fail when passed undefined input', async () => {
// @ts-expect-error undefined is non valid
await expect(ipfs.add(undefined)).to.eventually.be.rejected()
})

it('should fail when passed null input', async () => {
// @ts-expect-error null is non valid
await expect(ipfs.add(null)).to.eventually.be.rejected()
})

it('should wrap content in a directory', async () => {
const data = { path: 'testfile.txt', content: fixtures.smallFile.data }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
// eslint-disable-next-line complexity
module.exports = async function * normaliseInput (input, normaliseContent) {
if (input === null || input === undefined) {
return
throw errCode(new Error(`Unexpected input: ${input}`), 'ERR_UNEXPECTED_INPUT')
}

// String
Expand Down

0 comments on commit e9852ef

Please sign in to comment.