Skip to content

Commit

Permalink
Print error logs when collecting class reflections failed. (#6253)
Browse files Browse the repository at this point in the history

Co-authored-by: 李铭昕 <715557344@qq.com>
  • Loading branch information
xuanyanwow and limingxinleo committed Nov 2, 2023
1 parent 000373a commit e0adc9c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- [#6239](https://github.com/hyperf/hyperf/pull/6239) Improve amqp, use methods instead of `$delivery_info` and optimize `BeforeConsume` event.
- [#6250](https://github.com/hyperf/hyperf/pull/6250) Enhance scopeDoc for generateModelIdeVisitor.
- [#6253](https://github.com/hyperf/hyperf/pull/6253) Print error logs when collecting class reflections failed.

# v3.0.41 - 2023-10-27

Expand Down
16 changes: 15 additions & 1 deletion docs/en/quick-start/questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,18 @@ When using `hyperf/hyperf:8.0-alpine-v3.13-swoole` image
```dockerfile
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community/gnu-libiconv=1.15-r3
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
```
```

## DI Reflection Manager collect failed

When an exception occurs during the DI collection phase (for example, a namespace error), the output of a log in the following format may be generated.

- Service code, check the files and classes related to the path in the log.
- Framework code, submit PR feedback.
- Third party components, feedback to the component author.

```bash
[ERROR] DI Reflection Manager collecting class reflections failed.
File: xxxx.
Exception: xxxx
```
2 changes: 1 addition & 1 deletion docs/zh-cn/db/gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ return [

## 覆盖 Visitor

Hyperf 框架中,当使用 `gen:model` 时,默认只会将 `tinyint, smallint, mediumint, int, bigint` 声明为 `int` 类型,`bool, boolean` 声明为 `boolean` 类型,其他数据类型默认为`string`,可以通过重写覆盖调整。
Hyperf 框架中,当使用 `gen:model` 时,默认只会将 `tinyint, smallint, mediumint, int, bigint` 声明为 `int` 类型,`bool, boolean` 声明为 `boolean` 类型,其他数据类型默认为 `string` ,可以通过重写覆盖调整。

如下:

Expand Down
16 changes: 15 additions & 1 deletion docs/zh-cn/quick-start/questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ http2 => enabled

如果没有,需要重新编译 Swoole 并增加 `--enable-http2` 参数。

2. 检查 [server.php](/zh-cn/config?id=serverphp-配置说明) 文件中 `open_http2_protocol` 选项是否为 `true`
2. 检查 server.php 文件中 `open_http2_protocol` 选项是否为 `true`

## Command 无法正常关闭

Expand Down Expand Up @@ -203,3 +203,17 @@ ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community/ gnu-libiconv=1.15-r3
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
```

## DI 收集失败

在 DI 收集阶段发生异常(如命名空间错误等原因),可能产生以下格式日志的输出。

- 业务代码,排查日志中路径相关的文件和类。
- 框架代码,提交 PR 反馈。
- 第三方组件,反馈给组件作者。

```bash
[ERROR] DI Reflection Manager collecting class reflections failed.
File: xxxx.
Exception: xxxx
```
15 changes: 15 additions & 0 deletions docs/zh-hk/quick-start/questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,18 @@ ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community/ gnu-libiconv=1.15-r3
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
```


## DI 收集失敗

在 DI 收集階段發生異常(如命名空間錯誤等原因),可能產生以下格式日誌的輸出。

- 業務代碼,排查日誌中路徑相關的文件和類。
- 框架代碼,提交PR反饋。
- 第三方組件,反饋給組件作者。

```bash
[ERROR] DI Reflection Manager collecting class reflections failed.
File: xxxx.
Exception: xxxx
```
14 changes: 14 additions & 0 deletions docs/zh-tw/quick-start/questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,17 @@ ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community/ gnu-libiconv=1.15-r3
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
```

## DI 收集失敗

在 DI 收集階段發生異常(如名稱空間錯誤等原因),可能產生以下格式日誌的輸出。

- 業務程式碼,排查日誌中路徑相關的檔案和類。
- 框架程式碼,提交PR反饋。
- 第三方元件,反饋給元件作者。

```bash
[ERROR] DI Reflection Manager collecting class reflections failed.
File: xxxx.
Exception: xxxx
```
9 changes: 8 additions & 1 deletion src/di/src/ReflectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ReflectionMethod;
use ReflectionProperty;
use Symfony\Component\Finder\Finder;
use Throwable;

use function Hyperf\Support\value;

Expand Down Expand Up @@ -107,7 +108,13 @@ public static function getAllClasses(array $paths): array
continue;
}
$reflectionClasses[$className] = static::reflectClass($className);
} catch (\Throwable) {
} catch (Throwable $e) {
echo sprintf(
"\033[31m%s\033[0m",
'[ERROR] DI Reflection Manager collecting class reflections failed. ' . PHP_EOL .
"File: {$file->getRealPath()}." . PHP_EOL .
'Exception: ' . $e->getMessage()
) . PHP_EOL;
}
}
return $reflectionClasses;
Expand Down

0 comments on commit e0adc9c

Please sign in to comment.