hankcs/HanLP · error · RuntimeError
{err} The command is: {cmd}
Error message
{err}
The command is:
{cmd} What it means
run_cmd executes a shell command and, on a nonzero exit code, raises RuntimeError with the command's stderr followed by the exact command line. It is a thin wrapper around get_exitcode_stdout_stderr used by utilities like smatch_eval and official_conll_05_evaluate.
Source
Thrown at hanlp/utils/io_util.py:604
See https://stackoverflow.com/a/21000308/3730690
Args:
cmd: Command.
Returns:
Exit code, stdout, stderr.
"""
args = shlex.split(cmd)
proc = Popen(args, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
exitcode = proc.returncode
return exitcode, out.decode('utf-8'), err.decode('utf-8')
def run_cmd(cmd: str) -> str:
exitcode, out, err = get_exitcode_stdout_stderr(cmd)
if exitcode:
raise RuntimeError(err + '\nThe command is:\n' + cmd)
return out
@contextlib.contextmanager
def pushd(new_dir):
previous_dir = os.getcwd()
os.chdir(new_dir)
try:
yield
finally:
os.chdir(previous_dir)
def basename_no_ext(path):
basename = os.path.basename(path)
no_ext, ext = os.path.splitext(basename)
return no_ext
View on GitHub (pinned to ddb1299bdd)
Solutions
- Read the stderr at the top of the message — it states the underlying failure (command not found, syntax error, missing file).
- Fix prerequisites: install the tool, correct the paths, ensure input files exist.
- Reproduce by pasting the command shown after 'The command is:' into a shell for interactive debugging.
Defensive patterns
Strategy: try-catch
Validate before calling
import shutil
for tool in ['perl']:
assert shutil.which(tool), f'{tool} required for external eval' Try / catch
try:
out = run_cmd(cmd)
except RuntimeError as e:
log.error('external eval failed: %s', e)
raise Prevention
- Smoke-test external eval scripts in CI with tiny inputs.
- Wrap run_cmd and log both stderr and the command for reproducibility.
When it happens
Trigger: Calling run_cmd('perl script.pl ...') etc. when the external tool (perl script, evaluation binary) fails: missing executable, bad arguments, unreadable files, or evaluation-script internal errors.
Common situations: Missing perl/malt/etc. on PATH; wrong paths passed to bundled eval scripts; AMR/CoNLL05 evaluation on malformed inputs.
Related errors
- eval.pl exited with error code {exitcode} and error message
- Unsupported argument length: {item}
- If no `decoder_input_ids` or `decoder_inputs_embeds` are pas
- Conversion failed with code {code} for {src}. The err messag
- Failed to parse results from smatch: {line}
AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27).
Data as JSON: /api/errors/b454ec45f1640a79.
Report an issue: GitHub.