alibaba/arthas · error · IllegalArgumentException

必须提供 path 或 cursor

Error message

必须提供 path 或 cursor

What it means

Thrown by parseCursorOrArgs() in the ViewFile MCP tool when neither a cursor nor a non-empty path argument is provided. The tool reads a file slice by absolute/relative path or resumes from an opaque cursor token; at least one must be supplied.

Source

Thrown at core/src/main/java/com/taobao/arthas/core/mcp/tool/function/basic1000/ViewFileTool.java:120

    private static final class CursorRequest {
        private final String path;
        private final long offset;
        private final boolean cursorUsed;

        private CursorRequest(String path, long offset, boolean cursorUsed) {
            this.path = path;
            this.offset = offset;
            this.cursorUsed = cursorUsed;
        }
    }

    private CursorRequest parseCursorOrArgs(String path, String cursor, Long offset) {
        if (cursor != null && !cursor.trim().isEmpty()) {
            CursorValue decoded = decodeCursor(cursor.trim());
            return new CursorRequest(decoded.path, decoded.offset, true);
        }
        if (path == null || path.trim().isEmpty()) {
            throw new IllegalArgumentException("必须提供 path 或 cursor");
        }
        if (offset != null && offset < 0) {
            throw new IllegalArgumentException("offset 不允许为负数");
        }
        long resolvedOffset = (offset != null) ? offset : 0L;
        return new CursorRequest(path.trim(), resolvedOffset, false);
    }

    private static final class CursorValue {
        private final String path;
        private final long offset;

        private CursorValue(String path, long offset) {
            this.path = path;
            this.offset = offset;
        }
    }

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Provide a non-empty `path` (absolute or relative to an allowed root), or
  2. Provide a `cursor` token returned by a previous viewfile call to continue reading.

Example fix

// before
viewfile(path=null, cursor=null)
// after
viewfile(path="/var/log/app.log", offset=0)
Defensive patterns

Strategy: validation

Validate before calling

if ((cursor == null || cursor.trim().isEmpty())
        && (path == null || path.trim().isEmpty())) {
    throw new IllegalArgumentException("path or cursor required");
}

Type guard

static boolean hasViewFileTarget(String path, String cursor) {
    return (path != null && !path.trim().isEmpty())
        || (cursor != null && !cursor.trim().isEmpty());
}

Try / catch

null

Prevention

When it happens

Trigger: Calling the viewfile tool with path=null/empty and cursor=null/empty. The cursor branch is only taken when cursor is non-blank, so both being empty reaches this guard.

Common situations: Calling viewfile with no arguments; passing path="" by mistake; an MCP client omitting both fields in the request payload.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/b2c10696f2a7c8e3. Report an issue: GitHub.