Skip to content

Fix 'Attempt to read property metadata on null' in Webhooks controller#586

Open
proteusbr1 wants to merge 1 commit intopagarme:masterfrom
proteusbr1:fix/webhook-metadata-null
Open

Fix 'Attempt to read property metadata on null' in Webhooks controller#586
proteusbr1 wants to merge 1 commit intopagarme:masterfrom
proteusbr1:fix/webhook-metadata-null

Conversation

@proteusbr1
Copy link

Qual o tipo de PR é esse? (marque todos os aplicáveis)

  • Refatoração
  • Adição de funcionalidade
  • Correção de bug
  • Otimização
  • Atualização de documentação

Descrição

Este PR resolve o Warning: Attempt to read property "metadata" on null em Webhooks::handle_requests. O erro acontecia quando o payload do webhook não continha a estrutura completa de pedido (data->order).

Alterações realizadas:

  • Extração segura das propriedades $code e $metadata usando o operador de null coalescing (?? null).
  • Garante que valores nulos sejam tratados corretamente pelo método orderByWoocommerce sem gerar erros fatais/warnings.

Cenários testados

  • Cenário de Erro: Validado que payloads incompletos não causam mais exceções ao tentar ler metadados.

This commit adds safe property access (null coalescing) for webhook payload data, specifically preventing errors when 'data->order' is missing in the webhook body.
Copilot AI review requested due to automatic review settings January 2, 2026 16:47
@backstage-catalog-validator
Copy link

⚠️ Este repositório ainda não está catalogado no Backstage. ⚠️

Por favor, catalogue-o seguindo as instruções nesta documentação. [Via VPN].

💁 Qualquer problema ou dúvida, estamos no Slack, basta abrir um ticket no canal #help-foundation-platform.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a null pointer warning in the Webhooks controller that occurred when webhook payloads lacked a complete order structure. The fix extracts code and metadata properties safely using null coalescing operators before passing them to orderByWoocommerce().

Key changes:

  • Added null-safe extraction of $code from webhook payload
  • Added null-safe extraction of $metadata from nested order structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +64 to +65
$code = $body->data->code ?? null;
$metadata = $body->data->order->metadata ?? null;
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null coalescing operator only protects against the final property being null, not intermediate properties. If $body->data is null, this will still produce a "Attempt to read property on null" warning. Consider using the nullsafe operator ?-> instead, or check if $body->data exists first. For example: $code = $body->data?->code ?? null; and $metadata = $body->data?->order?->metadata ?? null;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant