Open
[L2] fix: raise 了一个字符串字面量(B016)→ 不支持的 mode 分支抛的是 TypeError,原始提示被吞 #6529
[L2] fix: raise 了一个字符串字面量(B016)→ 不支持的 mode 分支抛的是 TypeError,原始提示被吞 #6529
Open
eieieiAdd on Oct 1
eieiei
eieiei
Oct 1

描述

[L2] fix: raise 了一个字符串字面量(B016)→ 不支持的 mode 分支抛的是 TypeError,原。CI 流水线全 Job 通过(含 ruff check / ruff format / codespell / OAT 检查等),单提交、CLA yes。

变更类型

Bug 修复

关联的Issue

NA(代码质量修复,不涉及功能 Issue)

测试

  • CI 流水线全 Job 通过(含 ruff check / ruff format / codespell / OAT 等检查项)
  • 变更为最小化修复,不影响现有功能

文档更新

NA(无文档变更)

合入检查

关联 Issue: #1957

likedislike
Merge blocked
eieieieieiei
Oct 1 Created pull request, commit b3f800c6
atomgit-bot
atomgit-bot
Oct 1 Comments:

变更摘要

本 PR 修复 cmake/asc/legacy_modules/util/extract_host_stub.py 中 generate_launch_kernel_code 函数不支持的 mode 分支的异常抛出方式。原代码对字符串字面量执行 raise,不符合 Python 要求抛出 BaseException 子类或实例的约束,运行时会直接产生 TypeError: exceptions must derive from BaseException,导致原本的提示信息被吞掉。改动将该处改为抛出 ValueError,消息文本保持不变,使其与仓内 cmake/ 下既有的「参数/取值不合法」异常用法保持一致。

主要改动

  • 字符串字面量 raise 改为抛出 ValueError:在 generate_launch_kernel_code 的 else 分支中,raise ("[ERROR]: mode do not support!") 改为 raise ValueError("[ERROR]: mode do not support!"),使不支持的 mode 能正确抛出异常并保留原有提示文本。
  • 消除 B016 规则告警:该行原本会被 ruff 的 B016 Cannot raise a literal 规则命中,修改后不再触发该静态检查。
  • 异常语义沿用既有约定:选择 ValueError 与本仓 cmake/ 目录下同类「取值不合法」场景的异常用法一致,除该行外文件其余内容未变。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Oct 1 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Oct 1 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Oct 1 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
cmake ✅ 诸葛洵, wuyang_hw (2/2) ✅ 诸葛洵 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
CANN-robot
CANN-robotCollaborators
Oct 1 Comments:

CLA Signature Pass

wsnidie1, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Oct 1 Set zengjuan,zhanghao_0689,suqwe,wulinyu,kong0808,dengjing_aoe,YeZZzzz1,bluesky901,yangbinhua,zhudi22,chenyiyuan,xun_zhuge,XuebinYang,sjtulxh,bianque,houyuyang,Lycheeeee,YANXI_ZHAO,chentianyu19,shi_nanxiang,wuyang_hw,jiangxinyu3,ascendhjh,hujiawen_kaven,wangxiaozhi,DragonBornHD84,louyuxuan,hyolee,yukangchen as approver
CANN-robotCANN-robotCollaborators
Oct 1 Set xun_zhuge,chentianyu19 as approver
eieiei
eieiei
Oct 1 Comments:

/compile

likedislike
eieieieieiei
Oct 1 Pre merge succeeded (commit_id: 6d4e0c237c36171779fda2b586d0052cf662d237)
eieiei
eieiei
Oct 1 Comments:

这条是 cmake/asc/legacy_modules/util/extract_host_stub.py:860 的 raise ("[ERROR]: mode do not support!") —— raise 一个 str 会在运行时抛 TypeError: exceptions must derive from BaseException,所以这条“mode 不支持”的分支从来没成功报过错,原始提示被吞掉。改成 raise ValueError(...),消息一字未动;选 ValueError 是因为本仓 cmake/ 下已有大量 raise ValueError(...)(split_opc_json_with_op_list.py:35/38/41/48 等)。复验:ruff --select B016 由 1 条变 0 条(82 仓里 B016 总共也只有这 1 处命中)。

@chenyiyuan @sjtulxh @suqwe @bianque @shi_nanxiang 麻烦帮忙看下,谢谢。

likedislike
CANN-robot
CANN-robotCollaborators
Oct 1 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Oct 1 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 1 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 1 Added label: ci-pipeline-passed
eieiei
eieiei
Oct 22 Comments:

【同形缺陷的第二处,因他人 PR 占着同一文件,没有并入本 PR】

本机把 git grep -I -e 'raise ("' -e "raise ('" master 在 48 个 CANN 仓(本机有克隆的)里跑了一遍,全 CANN 只有 asc-devkit 一个仓、2 处,另一处不在本 PR 范围里:

master:cmake/asc/legacy_modules/util/extract_host_stub.py:860  ← 本 PR 改的就是这处
master:tools/build/asc_op_compile_base/common/buildcfg/buildcfg.py:56

第二处的上下文更能说明它是笔误——同一个函数里前两处都是对的:

def _check_kwargs(kwargs):
    if "tbe_debug_level" in kwargs.keys():
        if kwargs["tbe_debug_level"] not in (0, 1, 2):
            raise (
                Exception("Unsupported tbe_debug_level: …")     # ← 写法正确
            )
    if "vector_fp_ceiling" in kwargs.keys():
        if kwargs["vector_fp_ceiling"] not in (0, 1, 2):
            raise (Exception("Unsupported vector_fp_ceiling. …"))  # ← 写法正确
    if "compatible" in kwargs:
        if not isinstance(kwargs["compatible"], bool):
            raise ("'%s' should be a boolean variable" % (kwargs["compatible"]))   # ← 少了 Exception

本机复现(把 buildcfg.py 里 _check_kwargs 整段逐字抽出来跑,不改动任何一行,只加调用与捕获):

$ python3 harness.py            # 调用 _check_kwargs({'compatible': 'yes'})
TypeError: exceptions must derive from BaseException

⇒ 用户把 compatible 传成字符串时,看到的是 TypeError,而本该看到的「'yes' should be a boolean variable」被完全吞掉。这与本 PR 的 extract_host_stub.py:860 是同一类缺陷(B016),区别只是那里是 mode 兜底分支。

为什么没顺手一起改:GET /repos/cann/asc-devkit/pulls?state=open&per_page=100(4 页、347 条 open PR)逐条读 /pulls/{n}/files 后,!6478(@qq_45754000,fix(buildcfg): isolate context configurations)正在改 buildcfg.py。我不去抢同一个文件,所以把补丁留在这里:

-            raise ("'%s' should be a boolean variable" % (kwargs["compatible"]))
+            raise Exception("'%s' should be a boolean variable" % (kwargs["compatible"]))

另外提一句门禁为什么看不见这类缺陷,供以后加规则时参考:本仓钩子是 ruff-pre-commit v0.14.14,args 只有 --output-format github --fix --extend-ignore E402,E711,E712,E721,F401,F403,F405,F811,F821,F841,F523,E741,F601,而仓内 ruff.toml 没有 [lint] select ⇒ 实际生效的是 ruff 默认规则集(E4/E7/E9/F),bugbear 的 B016 根本不在选择集里,所以这两处不是「被豁免」,是从来没被查过。

likedislike
eieieieieiei
Oct 22 Modify description of pull request
eieiei
eieiei
27 days ago Comments:

@wuyang_hw 你好!这条 PR 的 CI 已全绿,挂了 27 天了。方便时帮忙看一眼给个 /lgtm 或 /approve 吗?如有问题我马上改,谢谢!

likedislike
eieieieieiei
26 days ago Modify description of pull request
吴洋
吴洋Collaborators
20 days ago Comments:

/lgtm
/approve

likedislike
zhugexun_sjtu
zhugexun_sjtuCollaborators
20 days ago Comments:

/lgtm
/approve

likedislike
CANN-robot
CANN-robotCollaborators
20 days ago Comments:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/approve: wuyang_hw

likedislike
CANN-robotCANN-robotCollaborators
20 days ago Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
20 days ago Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
20 days ago Comments:

The following label is not ready.

ci-pipeline-passed: The ci-pipeline-passed label is expired as added over 72 hours. Please use /compile to recompile.

likedislike
leozjr
leozjrCollaborators
13 days ago Comments:

compile

likedislike
eieieieieiei
13 days ago virtual merging failed, update merge request[project_id: 8547062, iid: 6529, target_commit_sha: c9fa126b384eaa947b118ab63c0ce4a4bc5ee7e6], message: You are not allowed to merge to this ref
eieieieieiei
13 days ago virtual merging failed, update merge request[project_id: 8547062, iid: 6529, target_commit_sha: c9fa126b384eaa947b118ab63c0ce4a4bc5ee7e6], message: You are not allowed to merge to this ref
CANN-robot
CANN-robotCollaborators
13 days ago Comments:
❌ CI 流水线启动失败
🚫 权限不足: 触发者 leozjr 仅有 read 权限(需 push 及以上权限或由 PR 创建者本人触发)
处理: 由 PR 创建者或有 push 权限的成员触发
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
13 days ago Added label: ci-pipeline-failed
CANN-robot
CANN-robotCollaborators
13 days ago Comments:

流水线分析报告 — asc-devkit run#7801

流水线: https://gitcode.com/CANN/asc-devkit/actions/runs/2f9774d4d4544a28bd033bcf0d2863a5 | PR#6529 | 2026-11-12 16:55:51 ~ 16:56:56 | 失败 Job 1 个

定界结论: 代码问题 / 门禁权限配置 — 触发者 leozjr 仅有 read 权限
  • 失败类型: 代码问题 / 门禁权限配置(权限校验拦截, 非代码缺陷)
  • 根因: Test_pre_pipeline 前置权限检查不通过 —— 触发者 leozjr 仅有 read 权限, 不满足"push 及以上权限或由 PR 创建者本人触发"的要求; 本 PR 作者为 wsnidie1。
  • 处置建议: 由 PR 创建者 wsnidie1 本人或具备 push 权限的仓库成员重新触发门禁即可; 权限满足前无需修改代码。
  • 排除项: 非代码缺陷、非环境抖动 —— 流水线在取码完成后、编译开始前即被权限门禁拦截, compile / UT / CodeCheck 等 20 个下游 Job 全部处于 INIT(级联未启动), 无独立失败。

失败根因分析

根因 #1: 代码问题 / 门禁权限配置 — 触发者 leozjr 仅有 read 权限
  • 判据: 门禁权限拦截: 触发者 leozjr 权限不足(需 push 及以上), 需 PR 创建者本人或 push 权限成员触发
  • 定位步骤: 1_pre_pipeline.log
  • 影响 Job: Test_pre_pipeline(失败); compile / Antipoison / CodeCheck_* / SCA / API_Check / ut / PreSmoke_* / UT_report 等 20 个 Job 为 INIT(级联未启动)
  • PR 信息: PR#6529 作者 wsnidie1, 分支 fix-raise-string-literal, 变更文件 1 个(cmake/asc/legacy_modules/util/extract_host_stub.py)
  • 根因证据(日志原文):
[2026-11-12 16:56:10.471+08:00] ❌ 目标仓库权限检查不通过: 触发者 **leozjr** 仅有 read 权限(需 push 及以上权限或由 PR 创建者本人触发)
结构化定界摘要
[{"repo": "asc-devkit", "run_number": 7801, "Failed_Type": "代码问题", "Failed_Sub_Type": "门禁权限配置", "Failed_Reason": "门禁前置权限检查不通过: 触发者 leozjr 仅有 read 权限(需 push 及以上), 需 PR 创建者 wsnidie1 本人或 push 权限成员触发", "evidence": "❌ 目标仓库权限检查不通过: 触发者 **leozjr** 仅有 read 权限(需 push 及以上权限或由 PR 创建者本人触发)", "suggestion": "由 PR 创建者 wsnidie1 本人或具备 push 权限的成员重新触发门禁", "jobs": "Test_pre_pipeline"}]

由门禁失败定界分析自动生成 | repo: asc-devkit | run: 2f9774d4d4544a28bd033bcf0d2863a5 | PR#6529

likedislike
leozjrleozjrCollaborators
13 days ago Deleted associated issue: [Bug-Report|缺陷反馈]: fix: raise 了一个字符串字面量(B016)→ 不支持的 mode 分支抛的是 TypeError,原始提示被吞
leozjrleozjrCollaborators
13 days ago Associated issue: [Bug-Report|缺陷反馈]: fix: raise 了一个字符串字面量(B016)→ 不支持的 mode 分支抛的是 TypeError,原始提示被吞
leozjrleozjrCollaborators
13 days ago Deleted associated issue: [Bug-Report|缺陷反馈]: fix: raise 了一个字符串字面量(B016)→ 不支持的 mode 分支抛的是 TypeError,原始提示被吞