@@ -803,8 +803,8 @@ private function processRouteAttributes(): void
803803 if ($ instance instanceof RouteAttributeInterface) {
804804 $ this ->routeAttributes ['class ' ][] = $ instance ;
805805 }
806- } catch (Throwable ) {
807- log_message ( ' error ' , ' Failed to instantiate attribute: ' . $ attribute ->getName ());
806+ } catch (Throwable $ e ) {
807+ $ this -> logRouteAttributeInstantiationFailure ( $ attribute ->getName (), $ this -> controller , null , $ e );
808808 }
809809 }
810810
@@ -823,14 +823,43 @@ private function processRouteAttributes(): void
823823 if ($ instance instanceof RouteAttributeInterface) {
824824 $ this ->routeAttributes ['method ' ][] = $ instance ;
825825 }
826- } catch (Throwable ) {
827- // Skip attributes that fail to instantiate
828- log_message ('error ' , 'Failed to instantiate attribute: ' . $ attribute ->getName ());
826+ } catch (Throwable $ e ) {
827+ $ this ->logRouteAttributeInstantiationFailure ($ attribute ->getName (), $ this ->controller , $ this ->method , $ e );
829828 }
830829 }
831830 }
832831 }
833832
833+ /**
834+ * Logs an attribute instantiation failure with the resolved route context.
835+ *
836+ * @param string $attributeName Fully qualified attribute class name.
837+ * @param string $controller Resolved controller class name.
838+ * @param string|null $method Resolved controller method name, if applicable.
839+ */
840+ private function logRouteAttributeInstantiationFailure (
841+ string $ attributeName ,
842+ string $ controller ,
843+ ?string $ method ,
844+ Throwable $ e ,
845+ ): void {
846+ $ location = $ controller ;
847+
848+ if ($ method !== null && $ method !== '' ) {
849+ $ location .= ':: ' . $ method . '() ' ;
850+ }
851+
852+ log_message (
853+ 'error ' ,
854+ 'Failed to instantiate route attribute "{attribute}" on "{location}": {message} ' ,
855+ [
856+ 'attribute ' => $ attributeName ,
857+ 'location ' => $ location ,
858+ 'message ' => $ e ->getMessage (),
859+ ],
860+ );
861+ }
862+
834863 /**
835864 * Execute beforeController() on all route attributes.
836865 * Called by CodeIgniter before controller execution.
0 commit comments