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 (#3818)
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 authored Aug 17, 2021
1 parent a201a3d commit 1343708
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions packages/interface-ipfs-core/src/pubsub/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module.exports = (factory, options) => {

it('should fail with undefined msg', async () => {
const topic = getTopic()
// @ts-ignore invalid parameter
await expect(ipfs.pubsub.publish(topic)).to.eventually.rejectedWith('argument "data" is required')
// @ts-expect-error invalid parameter
await expect(ipfs.pubsub.publish(topic)).to.eventually.be.rejected()
})

it('should publish message from buffer', () => {
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 1343708

Please sign in to comment.