# Troubleshooting

{% hint style="info" %}

* \<SERVICE-NAME> can be found in `make -f .stoobly/services/Makefile <WORKFLOW-NAME>/services`
* \<WORKFLOW-NAME> by default can either be record, mock, or test
  {% endhint %}

## After Running a Workflow

{% stepper %}
{% step %}
**Ensure two workflows are not running at the same time**

* Bring one workflow down before running another
  * e.g. `make -f .stoobly/services/Makefile <WORKFLOW-NAME>/down`
    {% endstep %}

{% step %}
**Double check expected containers are running**

* Ensure the proxy container for each service is running
  * e.g. `docker ps | grep <WORKFLOW-NAME>-<SERVICE-NAME>.proxy-1`
  * To learn about which containers should be running, see [here](https://docs.stoobly.com/core-concepts/scaffold/validation)
* If the workflow is either `record` , `mock` , or `test` ensure the gateway service is running
  * e.g. `docker ps | grep <WORKFLOW-NAME>-gateway.service-1`
    {% endstep %}

{% step %}
**Gather logs to search for errors**

* To view init logs run:
  * `make -f .stoobly/services/Makefile <WORKFLOW-NAME>/logs options="--container init"`
* To view service logs run:
  * `make -f .stoobly/services/Makefile <WORKFLOW-NAME>/logs`
    {% endstep %}

{% step %}
**Gather logs to trace request**

* Ensure that a request gets routed to the correct service container
  * To learn more about request service flow, see [here](https://docs.stoobly.com/core-concepts/scaffold/workflow)
* To view service logs run:
  * `make -f .stoobly/services/Makefile <WORKFLOW-NAME>/logs`
* To view gateway logs run:
  * `make -f .stoobly/services/Makefile <WORKFLOW-NAME>/logs options="--container service --service gateway"`
    {% endstep %}

{% step %}
**Use validate workflow command**

* To learn more about the command, see [here](https://docs.stoobly.com/guides/how-to-integrate-e2e-testing/how-to-run-a-workflow/troubleshooting/validating)
  {% endstep %}
  {% endstepper %}

## After Unexpected 5xx Error

{% stepper %}
{% step %}
**Double check system configuration**

* `/etc/hosts` contains the correct hostname(s)
  {% endstep %}

{% step %}
**Ensure CA certs are installed**

* Run either of the following:
  * `make -f .stoobly/services/Makefile ca-cert install`
  * `stoobly-agent ca-cert install`
  * For manual installation, see <https://docs.mitmproxy.org/stable/concepts-certificates/>
    {% endstep %}
    {% endstepper %}

## After 499 Status Code (Mock Not Found)

{% stepper %}
{% step %}
**Double check if the correct scenario is used**

* Double check if request exists in the scenario
* By default the UI is configured to run on <http://localhost:4200>
  {% endstep %}

{% step %}
**Double check rewrite rules**

* See `.stoobly/services/<SERVICE-NAME>/<WORKFLOW-NAME>/init`
* To learn more about rewrite rules, see [here](https://docs.stoobly.com/core-concepts/agent/proxy-settings/rewrite-rules)
  {% endstep %}

{% step %}
**Double check lifecycle hooks**

* See `.stoobly/services/<SERVICE-NAME>/<WORKFLOW-NAME>/lifecycle_hooks.py`
* To learn more about lifecycle hooks, see [here](https://docs.stoobly.com/core-concepts/agent/lifecycle-hooks)
  {% endstep %}

{% step %}
**Double check match rules**

* See `.stoobly/services/<SERVICE-NAME>/<WORKFLOW-NAME>/init`
* To learn more about match rules, see [here](https://docs.stoobly.com/core-concepts/agent/proxy-settings/match-rules)
  {% endstep %}

{% step %}
**Gather logs to confirm correct application of rules (if any)**

* Search in the service logs to see if any rewrite rules are applied
* To view service logs run:
  * `make -f .stoobly/services/Makefile <WORKFLOW-NAME>/logs`
    {% endstep %}
    {% endstepper %}

## After Incorrect Response Returned

{% stepper %}
{% step %}
**Double check if the correct scenario is used**

* Double check if request exists in the scenario
* By default the UI is configured to run on <http://localhost:4200>
  {% endstep %}

{% step %}
**Create an Endpoint to enable component specific matching**

* To learn more, see [here](https://docs.stoobly.com/experimental/experimental-features/endpoints)
  {% endstep %}
  {% endstepper %}
