全库 9228 条 Python 运行时错误在判题沙箱里重跑了一遍(9028 条复现),按真实回溯重定归类表:
- TypeError 原来只认 12 种句式,633 条掉进兜底,一律被说成「把文字当成数字」。
实际多半是函数用法错:参数个数不对(点名 append / insert 并给正确写法)、
end= 拼成 enp=、list.index(x) 该写变量名.index(x)、忘写 ()(int(input)、
input[0],约 200 条)、拿 print() / append() 的返回值去算(约 100 条)等。
兜底从 633 条降到 64 条,ValueError 从 336 降到 5(split("")、%.2f 写错、
值不在列表里)。
- input[0] 原来被说成「对一个数字用了下标」:值的类型名比句式更说明问题,
builtin_function_or_method / NoneType 先于句式判。类型名来自代码不来自输入。
- AttributeError 带上 Python 的「Did you mean」(spilt → split 一种就 188 条),
s.len() 说成函数不是方法,数字没有 split() 说顺序反了。
- 「input() 读进来的是文字」只在学生代码里真有 input( 时才说。
- C:信号 31(system("pause") 被沙箱拦 / 字符数组溢出)和 25(死循环打印)
原来只有「崩溃了」,占 C 运行时错误一半多;void main 不再说成「要写 return 0」。
已经存进库的诊断没有新的 kind,旧提交看到的是新的中性兜底话。
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
1.7 KiB
Vue
68 lines
1.7 KiB
Vue
<script setup lang="ts">
|
||
import { clearErrorMark, showErrorMark } from "oj/problem/utils/errorMark"
|
||
import { explainRuntimeError, type RuntimeErrorInfo } from "oj/problem/utils/runtimeError"
|
||
|
||
/**
|
||
* 运行时错误的中文说明卡片(诊断由后端 judge/runtime-diagnosis.ts 给)。
|
||
* 知道是第几行的,就把那一行代码摆出来,并在编辑器里标红;卸掉时清掉标记。
|
||
*/
|
||
const props = defineProps<{
|
||
info: RuntimeErrorInfo
|
||
/** 这次提交的代码,用来摆出出错的那一行 */
|
||
code: string
|
||
}>()
|
||
|
||
const message = computed(() => explainRuntimeError(props.info, props.code))
|
||
|
||
const sourceLine = computed(() => {
|
||
const line = props.info.line
|
||
if (!line) return null
|
||
const text = props.code.split("\n")[line - 1]
|
||
return text?.trim() ? text.trim() : null
|
||
})
|
||
|
||
watch(
|
||
() => props.info.line,
|
||
(line) => {
|
||
if (line) showErrorMark(line, null, null)
|
||
else clearErrorMark()
|
||
},
|
||
{ immediate: true },
|
||
)
|
||
|
||
onUnmounted(clearErrorMark)
|
||
</script>
|
||
|
||
<template>
|
||
<n-card embedded class="explain-card">
|
||
<n-flex vertical :size="12">
|
||
<div class="explain">
|
||
<b v-if="info.line">第 {{ info.line }} 行运行时出错:</b>{{ message }}
|
||
</div>
|
||
<pre v-if="sourceLine" class="explain-code">{{ sourceLine }}</pre>
|
||
</n-flex>
|
||
</n-card>
|
||
</template>
|
||
|
||
<style scoped>
|
||
/* 结果弹窗不限宽,长句子不折行会把弹窗撑出屏幕 */
|
||
.explain-card {
|
||
max-width: 560px;
|
||
}
|
||
|
||
.explain {
|
||
font-size: 16px;
|
||
line-height: 1.7;
|
||
}
|
||
|
||
.explain-code {
|
||
margin: 0;
|
||
padding: 8px 12px;
|
||
border-radius: 4px;
|
||
font-size: 15px;
|
||
white-space: pre-wrap;
|
||
word-break: break-all;
|
||
background-color: rgba(208, 48, 80, 0.12);
|
||
}
|
||
</style>
|