-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Validate config and provide good error messages if something is wrong #1193
Comments
@thiagodelgado111 I'm not sure if I understand - removing the non existent protocol |
Hi @dryajov, thanks for helping! So, removing the non-existent protocol from the config file fixed it! Nevertheless, It took me a while to figure out the problem was in the config file though, would it be possible to either validate the config object before writing it, ignore the version read from disk if it fails and use the config object or ask users to check the config file when it happens? |
Thanks for clarifying @thiagodelgado111 - I agree ipfs should behave in a more user-friendly way when handling issues like this. Perhaps this is a good place to start a discussion around this? //cc @hacdias @daviddias @richardshneider @victorbjelkholm |
No need for discussion, @thiagodelgado111 is right. The API should empower the developer by providing good error messages and validate inputs. That's how we get good UX. |
A config error cannot be caught, or listened for and will cause the process to exit. const IPFS = require('ipfs')
console.log('IPFS node starting')
let node
try {
node = new IPFS({
"config": {
"Addresses": {
"Swarm": [ "rekt" ]
}
}
})
console.log('invalid config did not throw')
} catch (err) {
console.log('invalid config threw error')
throw err
}
node.once('ready', () => {
console.log('IPFS node ready...')
})
node.on('error', (err) => {
console.log('invalid config emitted error', err)
})
process.on('uncaughtException', (err) => {
console.log('invalid config caused uncaughtException')
throw err
}) Output: $ npm ls ipfs && node ipfs-config-bug.js
/Users/alan/Desktop/test
└── ipfs@0.27.7
IPFS node starting
invalid config did not throw
invalid config caused uncaughtException
/Users/alan/Desktop/test/ipfs-config-bug.js:30
throw err
^
Error: no protocol with name: rekt
at Protocols (/Users/alan/Desktop/test/node_modules/multiaddr/src/protocols-table.js:17:11)
at stringToStringTuples (/Users/alan/Desktop/test/node_modules/multiaddr/src/codec.js:45:19)
at stringToBuffer (/Users/alan/Desktop/test/node_modules/multiaddr/src/codec.js:170:13)
at Object.fromString (/Users/alan/Desktop/test/node_modules/multiaddr/src/codec.js:178:10)
at new Multiaddr (/Users/alan/Desktop/test/node_modules/multiaddr/src/index.js:39:25)
at Multiaddr (/Users/alan/Desktop/test/node_modules/multiaddr/src/index.js:27:12)
at config.Addresses.Swarm.forEach (/Users/alan/Desktop/test/node_modules/ipfs/src/core/components/pre-start.js:27:22)
at Array.forEach (<anonymous>)
at waterfall (/Users/alan/Desktop/test/node_modules/ipfs/src/core/components/pre-start.js:26:34)
at nextTask (/Users/alan/Desktop/test/node_modules/async/waterfall.js:16:14) |
ProductName: Mac OS X
ProductVersion: 10.12.6
BuildVersion: 16G1114
Type: Bug
Severity: Medium
Description:
If an invalid protocol is specified in Ipfs' config constructor argument, it will be persisted and then pre-start keeps failing due to the invalid protocol – even after changing the config.
Steps to reproduce the error:
Protocol used on
Addresses.Swarm
config list/ip6/::/etcp/4001
After fixing the config object
Same error even though not using that protocol anymore. Editing
.jsipfs/config
file removing the bad line solved it.The text was updated successfully, but these errors were encountered: