Skip to content

Broken error handling in vernemq.sh #422

@micw

Description

@micw

The error handling code in vernemq.sh is ambigous and wrong:

# Check configuration file
/vernemq/bin/vernemq config generate 2>&1 > /dev/null | tee /tmp/config.out | grep error

if [ $? -ne 1 ]; then
    echo "configuration error, exit"
    echo "$(cat /tmp/config.out)"
    exit $?
fi

The 1st line produces always an empty /tmp/config.out. Exit code of "grep error" is always 1, so the following blok is never executed.

Then at the very end vernemq is started (even if the config generation has an error. It prints:

Error generating config with cuttlefish
  run `vernemq config generate -l debug` for more information.

(I assume it runs cuttlefish internally again). Then it exists with exit code 1

The text "configuration error, exit" is never displayed.

More findings:
The message "Error generating config with cuttlefish" comes from env.sh in vernemq itself. There cuttlefish is called directly and obviously uses "exit 1" - so ne "grep error" magic required:

CONFIG_ARGS=`$CUTTLEFISH_COMMAND_PREFIX generate`
if [ "$?" -ne 0 ]; then
    echoerr "Error generating config with cuttlefish"
    echoerr "  run \`$RUNNER_SCRIPT config generate -l debug\` for more information."
    exit 1
fi

That's the clean way to handle config errors. The stuff in the vernemq.sh is just a dirty workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions