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

Commit

Permalink
Better error when account index doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincburns committed Feb 14, 2018
1 parent 0ee683f commit a48a99d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/statemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ StateManager.prototype.initialize = function(options, callback) {
this.unlocked_accounts = (options.unlocked_accounts || []).reduce(function(obj, address) {
// If it doesn't have a hex prefix, must be a number (either a string or number type).
if ((address + "").indexOf("0x") != 0) {
address = accounts[parseInt(address)].address.toLowerCase();
let idx = parseInt(address)
let account = accounts[idx]
if (!account) {
throw new Error(`Account at index ${idx} not found. Max index available is ${accounts.length - 1}.`)
}
address = account.address.toLowerCase();
}

obj[address.toLowerCase()] = true; // can be any value
Expand Down

0 comments on commit a48a99d

Please sign in to comment.