alibaba/arthas · error · IllegalArgumentException
offset 不允许为负数
Error message
offset 不允许为负数
What it means
Thrown by parseCursorOrArgs() in the ViewFile MCP tool when an explicit offset argument is supplied that is negative. The offset is a byte position into the file and must be >= 0. (This guard is for the args path, not the cursor path.)
Source
Thrown at core/src/main/java/com/taobao/arthas/core/mcp/tool/function/basic1000/ViewFileTool.java:123
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;
}
}
private CursorValue decodeCursor(String cursor) {
try {
byte[] jsonBytes = Base64.getUrlDecoder().decode(cursor);View on GitHub (pinned to 21cf2e9ba5)
Solutions
- Pass offset >= 0, or omit offset to default to 0.
- To read near the end, first query file size and compute a non-negative offset.
Example fix
// before viewfile(path="/var/log/app.log", offset=-512) // after viewfile(path="/var/log/app.log", offset=0)
Defensive patterns
Strategy: validation
Validate before calling
if (offset != null && offset < 0) {
throw new IllegalArgumentException("offset must be >= 0");
} Type guard
static boolean isValidOffset(Long offset) {
return offset == null || offset >= 0;
} Try / catch
null
Prevention
- Pass offset >= 0, or omit it to default to 0.
- Compute tail-read offsets from a known file size, never as a negative.
When it happens
Trigger: Calling viewfile with path set and offset < 0, e.g. offset=-1024, without a cursor.
Common situations: Passing a negative seek position intending to read the tail (the tool is offset-based, not tail-based); arithmetic error computing an offset; sign mistake.
Related errors
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/5ddb526cab28faeb.
Report an issue: GitHub.