521xueweihan/HelloGitHub · error · InputError

Input error: Must be number

Error message

Input error: Must be number

What it means

This InputError('Input error: Must be number') is raised in main() inside a try/except around `input_arg = input_list[1]` (script/make_content/make_content.py:88-91). Because the preceding check already guarantees len(sys.argv) == 2, indexing sys.argv[1] can never fail, so this branch is effectively dead code: the message suggests a non-numeric argument was rejected, but no numeric validation actually exists anywhere in main().

Source

Thrown at script/make_content/make_content.py:91

    for fi_dir in dir_list:
        # 忽略‘script’的目录
        if os.path.isdir(fi_dir) and 'script' not in fi_dir:
            make_content(fi_dir)


def main():
    """
    入口方法
    """
    input_list = sys.argv  # 获取输入的参数

    if len(input_list) != 2:
        raise InputError('Input error: Need a param')
    else:
        try:
            input_arg = input_list[1]
        except Exception:
            raise InputError('Input error: Must be number')
    if len(input_arg) == 1:
        make_content('0' + input_arg)
    elif input_arg == 'all':
        make_all_content()
    else:
        make_content(input_arg)

if __name__ == '__main__':
    main()

View on GitHub (pinned to 1bbd16c33e)

Solutions

  1. If you intend to validate that the argument is a number, replace the useless try/except with an explicit check: `if not (input_arg == 'all' or input_arg.isdigit()): raise InputError('Input error: Must be number')`.
  2. If refactoring main(), keep the strict `len(sys.argv) != 2` guard before any indexing so this dead branch stays dead or can be removed.
  3. Delete the try/except entirely (indexing is provably safe) and rely on the length check plus the isdigit check from step 1.

Example fix

# before (dead code: sys.argv[1] cannot raise after the length check)
try:
    input_arg = input_list[1]
except Exception:
    raise InputError('Input error: Must be number')

# after (actually validates the value)
input_arg = input_list[1]
if input_arg != 'all' and not input_arg.isdigit():
    raise InputError('Input error: Must be number')
Defensive patterns

Strategy: validation

Validate before calling

import sys

arg = sys.argv[1] if len(sys.argv) == 2 else None
if arg is not None and arg != 'all' and not arg.isdigit():
    sys.stderr.write('Input error: Must be number\n')
    sys.exit(1)

Type guard

def is_valid_period_arg(arg):
    """True for 'all' or a digit-only period number like '05'."""
    return arg == 'all' or (isinstance(arg, str) and arg.isdigit())

Try / catch

from make_content import InputError, main

try:
    main()
except InputError as e:
    sys.stderr.write(str(e.message) + '\n')
    sys.exit(2)

Prevention

When it happens

Trigger: Not reachable in the current code: the except only fires if input_list[1] raised, which cannot happen once len(input_list) == 2 is confirmed. It would only fire after a refactor that removes or weakens the length check while keeping the try/except. Passing a non-numeric argument (e.g. 'abc') today does NOT raise it — it falls through to make_content('abc') and fails later on missing paths.

Common situations: Developers see this string in the source and assume non-numeric input is validated; refactors that reorder the argv checks; copies of this script where the length guard was deleted, making the except suddenly live; debugging why 'abc' does not produce this error.

Related errors


AI-assisted analysis of 521xueweihan/HelloGitHub@1bbd16c33e (2026-08-14). Data as JSON: /api/errors/0def4d80292464e8. Report an issue: GitHub.