Fix error message panic in command result parsing #502
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When adding new mounts towards Azure Datalakes to the terraform configuration, it would sometimes cause a terraform crash. Mostly because of missing permissions on the container or the network blocked the traffic. Seemed like the error came from a HTTP 403 that came back to the commands running in databricks and it couldn't parse this when that error message came back to terraform.
Related issue filed earlier with the error message: #448
I identified that the problem in the parsing was the error message matching in the response from databricks, where with this particular kind of results gave an empty error message from the regular expression here:
https://github.com/databrickslabs/terraform-provider-databricks/blob/67c7713895d8f71a29958fe0e04901c7b5827608/compute/commands.go#L26
https://github.com/databrickslabs/terraform-provider-databricks/blob/67c7713895d8f71a29958fe0e04901c7b5827608/compute/commands.go#L105
This problem was fixed by changing the capture group from
(.*)
to(.+)
, thus changing it to only allow 1 or more characters. Then it can go down to the default error output, when no error message is found. This prevents panic and the following terraform crash.However the error message wasn't explaining much with the default summary, so I also added a new regular expressions to capture the best explaining error message from these kind of command errors. Where it picks up on an execution error, and the status code and description.
This results in the following error message displayed:
Example error from the command response
Hope this is an expectable way of catching this error, and give useful feedback to the user.