fix: Ensure DANFSE artifacts are correctly generated with improved error logging#143
Merged
Conversation
…ror logging Problem ------- In production, DANFSE (PDF) generation failed with HTTP 400 errors from the gateway, and temporary certificate files were deleted before being used. Solutions --------- 1. Transport Certificate Management: - Add fallback from /dev/shm to sys_get_temp_dir() when /dev/shm unavailable - Handles production environments with restricted memory-backed storage 2. Certificate Cleanup Sequencing: - Move cleanup to AFTER storeArtifacts() completes in emit(), refresh(), reemit() - Ensures getDanfse() calls complete before certificate cleanup occurs - Prevents 'Unable to set local cert chain file' errors 3. Enhanced Error Logging: - Capture full exception details: class, message, code, stack trace - Log XML payload information: length and first 200 characters - Enables diagnosis of HTTP 400 gateway rejections Changes ------- - Support/TransportCertificateManager.php: Fallback directory strategy - Http/Controllers/InvoiceController.php: Cleanup sequencing + detailed logging - tests/Unit/Http/Controllers/TransportCertificateCleanupTest.php: New test - tests/Unit/Http/Controllers/InvoiceControllerTest.php: Updated assertions Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
In production, DANFSE (PDF) generation failed intermittently:
/dev/shmaccess failed silentlyRoot Causes
Certificate Cleanup Timing
Transport certificates (
/dev/shm/nfse_tls_cert_*) were deleted beforestoreArtifacts()completed:Limited Error Visibility
Gateway HTTP 400 errors lacked debugging context:
Directory Availability Issues
/dev/shmmay be unavailable in some production environments.Solutions Implemented
1. Smart Temporary Directory Selection
2. Fixed Cleanup Sequencing
Moved cleanup to AFTER all client operations complete:
emit(): Cleanup afterstoreArtifacts()completesrefresh(): Cleanup afterstoreArtifacts()completesreemit(): Cleanup afterstoreArtifacts()completes3. Comprehensive Error Logging
Capture complete exception information:
exception_class: The exception typeexception_message: Error messageexception_code: Error codetrace: Full stack tracerawXml_length&rawXml_sample: XML payload detailsTesting
TransportCertificateCleanupTestvalidates certificate availability during DANFSE generationChanges
Support/TransportCertificateManager.php: Fallback directory logicHttp/Controllers/InvoiceController.php: Cleanup sequencing + enhanced loggingtests/Unit/Http/Controllers/TransportCertificateCleanupTest.php: New testtests/Unit/Http/Controllers/InvoiceControllerTest.php: Updated test assertions