Skip to content

D1 create doesn't print to standard error command-stderr #382

@serban-mihai

Description

@serban-mihai

I didn't try other commands yet, but I've tried with multiple wrangler versions and action versions and it always return blank to command-stderr (when trying to create a database that already exists).
The error output is printed to the step but when I try to pass it to another step to handle it it's blank. command-output is available when the creation works properly.

This is very inconvenient since it needs me to run another step only to check with info or list if the database has been already created.
Additionally the entire steps.deploy_step.outputs object is empty when the wrangler action returns 1.

I always pass the correctly inputs to the workflow_dispatch trigger.

jobs:
  create-database:
    runs-on: ubuntu-latest
    name: Create Resources
    outputs:
      deploy_failed: ${{ steps.check_result.outputs.deploy_failed }}
    steps:
       - name: Deploy Database
          uses: cloudflare/wrangler-action@v3
          id: deploy_step
          continue-on-error: true
          with:
            apiToken: ${{ secrets.... }}
            accountId: ${{ secrets.... }}
            command: |
              d1 create ${{ github.event.inputs.database-name }} --location ${{ github.event.inputs.preferred-location }}
            wranglerVersion: "4.24.3"
      - name: Set deploy failure flag
          id: check_result
          run: |
            echo "Raw wrangler output:"
            echo "$CMD_OUTPUT" # Data only when previous step exited with 0
          
            echo "Raw wrangler error:"
            echo "$CMD_ERROR" # Always empty, even if previous step exited with 1
          
            if [ "${{ steps.deploy_step.outcome }}" != "success" ]; then
              echo "deploy_failed=true" >> $GITHUB_OUTPUT
              if echo "$CMD_OUTPUT" | grep -qi "already exists"; then
                echo "crash_reason=already_exists" >> $GITHUB_OUTPUT
              else
                echo "crash_reason=unknown_error" >> $GITHUB_OUTPUT
              fi
            else
              echo "deploy_failed=false" >> $GITHUB_OUTPUT
              echo "crash_reason=none" >> $GITHUB_OUTPUT
            fi
          env:
            CMD_OUTPUT: ${{ steps.deploy_step.outputs.command-output }}
            CMD_ERROR: ${{ steps.deploy_step.outputs.command-stderr }}
            # CMD_ERROR: ${{ toJson(steps.deploy_step.outputs) }} # Always {}

Is there any way to get the error output?
I need the specific reason for the failure to further trigger other actions accordingly.

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