diff --git a/bin/oce-import-codes b/bin/oce-import-codes index 183fc18..4b62456 100755 --- a/bin/oce-import-codes +++ b/bin/oce-import-codes @@ -53,7 +53,7 @@ try { $application->add(new ImportCodesCommand()); $application->setDefaultCommand('import', true); $application->run(); -} catch (Exception $e) { +} catch (Throwable $e) { echo "Error: " . $e->getMessage() . "\n"; exit(1); } diff --git a/build.php b/build.php index df02fe8..7d038b6 100755 --- a/build.php +++ b/build.php @@ -80,7 +80,7 @@ echo " Size: " . number_format(filesize($pharFile)) . " bytes\n"; echo " Usage: ./build/oce-import-codes.phar RXNORM /path/to/rxnorm.zip --openemr-path=/var/www/openemr\n"; -} catch (Exception $e) { +} catch (Throwable $e) { echo "❌ Error building PHAR: " . $e->getMessage() . "\n"; exit(1); } diff --git a/src/Command/ImportCodesCommand.php b/src/Command/ImportCodesCommand.php index e979930..9ee3797 100644 --- a/src/Command/ImportCodesCommand.php +++ b/src/Command/ImportCodesCommand.php @@ -182,7 +182,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Initialize OpenEMR connection try { $this->connector->initialize($openemrPath, $site); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->logJson('error', 'Failed to initialize OpenEMR connection', ['error' => $e->getMessage()]); return Command::FAILURE; } @@ -359,7 +359,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->logJson('success', 'Import completed successfully'); return Command::SUCCESS; - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->logJson('error', 'Import failed', ['error' => $e->getMessage()]); // Cleanup on error @@ -383,7 +383,7 @@ private function performImport( if (!$dryRun) { try { $this->importer->import($codeType, $isWindows, $usExtension, $filePath); - } catch (\Exception $e) { + } catch (\Throwable $e) { // Check if this is a lock acquisition failure if (str_contains($e->getMessage(), 'Failed to acquire database lock')) { throw new CodeImportException("Import failed: " . $e->getMessage()); diff --git a/src/Service/CodeImporter.php b/src/Service/CodeImporter.php index 6753297..f7019fa 100644 --- a/src/Service/CodeImporter.php +++ b/src/Service/CodeImporter.php @@ -243,7 +243,7 @@ public function isVocabularyLoaded(string $codeType): bool ); return $result && $result['count'] > 0; - } catch (\Exception) { + } catch (\Throwable) { // If query fails, assume not loaded to be safe return false; } @@ -412,7 +412,7 @@ private function releaseLock(): void try { sqlQuery("SELECT RELEASE_LOCK(?)", [$this->currentLockName]); - } catch (\Exception $e) { + } catch (\Throwable $e) { // Log error but don't throw exception during cleanup error_log("Warning: Failed to release database lock '{$this->currentLockName}': " . $e->getMessage()); } finally { diff --git a/src/Service/OpenEMRConnector.php b/src/Service/OpenEMRConnector.php index a0e8b13..8ad4588 100644 --- a/src/Service/OpenEMRConnector.php +++ b/src/Service/OpenEMRConnector.php @@ -71,7 +71,7 @@ public function initialize(string $openemrPath, string $site = 'default'): void } else { throw new OpenEMRConnectorException("OpenEMR database functions not available"); } - } catch (\Exception $e) { + } catch (\Throwable $e) { throw new OpenEMRConnectorException("OpenEMR database connection test failed: " . $e->getMessage()); } diff --git a/tests/E2E/RealVocabularyImportE2ETest.php b/tests/E2E/RealVocabularyImportE2ETest.php index 8b2245b..2a0e6ff 100644 --- a/tests/E2E/RealVocabularyImportE2ETest.php +++ b/tests/E2E/RealVocabularyImportE2ETest.php @@ -64,7 +64,7 @@ protected function setUp(): void $this->connector = new OpenEMRConnector(); try { $this->connector->initialize(self::OPENEMR_PATH, self::SITE); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->markTestSkipped('OpenEMR initialization failed: ' . $e->getMessage()); } } @@ -307,7 +307,7 @@ private function getTableCount(string $tableName): int $result = $this->connector->querySql("SELECT COUNT(*) as cnt FROM `{$tableName}`"); return (int) ($result['cnt'] ?? 0); - } catch (\Exception) { + } catch (\Throwable) { return 0; } } diff --git a/tests/E2E/VocabularyImportE2ETest.php b/tests/E2E/VocabularyImportE2ETest.php index f5424f2..61a2635 100644 --- a/tests/E2E/VocabularyImportE2ETest.php +++ b/tests/E2E/VocabularyImportE2ETest.php @@ -55,7 +55,7 @@ protected function setUp(): void $this->connector = new OpenEMRConnector(); try { $this->connector->initialize(self::OPENEMR_PATH, self::SITE); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->markTestSkipped('OpenEMR initialization failed: ' . $e->getMessage()); } diff --git a/tests/Integration/ImportCodesIntegrationTest.php b/tests/Integration/ImportCodesIntegrationTest.php index 0d95591..15cbc11 100644 --- a/tests/Integration/ImportCodesIntegrationTest.php +++ b/tests/Integration/ImportCodesIntegrationTest.php @@ -58,7 +58,7 @@ protected function setUp(): void try { $this->connector->initialize(self::OPENEMR_PATH, self::SITE); $this->openemrAvailable = true; - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->markTestSkipped('OpenEMR initialization failed: ' . $e->getMessage()); } }