Skip to content

Commit

Permalink
[#759] Add smooth handling for network errors
Browse files Browse the repository at this point in the history
Problem: When network flag is used with tezos-node
config if url provided is not working, the binary
exits with a nasty error message

Solution: Add a handler that will pretty print the error
message should it occur on a command that uses
--network flag
  • Loading branch information
PruStephan committed Dec 30, 2023
1 parent 12bef3f commit 44b84ec
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Formula/tezos-node-ghostnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def install
"$@"
fi
# Check if config initialization did not failed due to incorrect network url
if [ $? -eq 124 ]; then
echo "Error: provided network config url is incorrect"
exit 1
fi
# Launching the node
if [[ -z "$CERT_PATH" || -z "$KEY_PATH" ]]; then
exec "$node" run --config-file="$config_file"
Expand Down
6 changes: 6 additions & 0 deletions Formula/tezos-node-mainnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def install
"$@"
fi
# Check if config initialization did not failed due to incorrect network url
if [ $? -eq 124 ]; then
echo "Error: provided network config url is incorrect"
exit 1
fi
# Launching the node
if [[ -z "$CERT_PATH" || -z "$KEY_PATH" ]]; then
exec "$node" run --config-file="$config_file"
Expand Down
13 changes: 11 additions & 2 deletions Formula/tezos-node-nairobinet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ def install
echo "Configuring the node..."
"$node" config init \
--rpc-addr "$NODE_RPC_ADDR" \
--network=https://teztnets.xyz/nairobinet\
--network=https://teztnets.xyz/anairobinet\
"$@"
else
echo "Updating the node configuration..."
"$node" config update \
--rpc-addr "$NODE_RPC_ADDR" \
--network=https://teztnets.xyz/nairobinet\
--network=https://teztnets.xyz/anairobinet\
"$@"
fi
# Check if config initialization did not failed due to incorrect network url
if [ $? -eq 124 ]; then
echo "Error: provided network config url is incorrect"
exit 1
fi
# Launching the node
if [[ -z "$CERT_PATH" || -z "$KEY_PATH" ]]; then
exec "$node" run --config-file="$config_file"
Expand All @@ -62,5 +68,8 @@ def install
def post_install
mkdir_p "#{var}/lib/tezos/node-nairobinet"
system "octez-node", "config", "init", "--data-dir" "#{var}/lib/tezos/node-nairobinet", "--network", "https://teztnets.xyz/nairobinet"
if $?.exitstatus == 124
raise "Error: could not init config with network with \"https://teztnets.xyz/nairobinet\" url"
end
end
end
11 changes: 9 additions & 2 deletions baking/src/tezos_baking/tezos_setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ def __init__(self, actual_sha256=None, expected_sha256=None):
self.actual_sha256 = actual_sha256
self.expected_sha256 = expected_sha256

class IncorrectConfigNetworkUrlProvided(Exception):
"Raised when config initialization failed because of incorrect network url provided"

def __init__(self, network_url):
self.network_url = network_url

class InterruptStep(Exception):
"Raised when there is need to interrupt step handling flow."
Expand Down Expand Up @@ -412,15 +417,17 @@ def check_blockchain_data(self):
print_and_log("The Tezos node data directory has not been configured yet.")
print_and_log(" Configuring directory: " + node_dir)
network = self.config["network"]
proc_call(
proc_res = proc_call(
"sudo -u tezos octez-node-"
+ self.config["network"]
+ " config init"
+ " --network "
+ network_name_or_teztnets_url(self.config["network"])
+ network_name_or_teztnets_url(network)
+ " --rpc-addr "
+ self.config["node_rpc_addr"]
)
if proc_res.returncode == 124:
raise IncorrectConfigNetworkUrlProvided(network_name_or_teztnets_url(network))

diff = node_dir_contents - node_dir_config
if diff:
Expand Down
Binary file added docker/octez-node
Binary file not shown.
4 changes: 4 additions & 0 deletions docker/package/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ def mk_node_unit(
node_postinst_steps += f"""
mkdir -p /var/lib/tezos/node-{network}
[ ! -f /var/lib/tezos/node-{network}/config.json ] && octez-node config init --data-dir /var/lib/tezos/node-{network} --network {network_config}
if [ $? -eq 124 ]; then
echo "Error: provided network config url is incorrect"
exit 1
fi
chown -R tezos:tezos /var/lib/tezos/node-{network}
"""

Expand Down
4 changes: 4 additions & 0 deletions docker/package/scripts/tezos-node-start
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if [[ -z "${CUSTOM_NODE_CONFIG:-}" ]]; then
${NETWORK:+"--network=$NETWORK"} \
"$@"
fi
if [ $? -eq 124 ]; then
echo "Error: provided network config url is incorrect"
exit 1
fi
node_run_args=("--config-file" "$config_file")
else
echo "Run using custom node config file"
Expand Down

0 comments on commit 44b84ec

Please sign in to comment.