Skip to content

identify the function and line in cfunction parse errors - #831

Closed
mvanhorn wants to merge 1 commit into
Earthcomputer:fabricfrom
mvanhorn:fix/759-cfunction-parse-errors
Closed

mvanhorn wants to merge 1 commit into
Earthcomputer:fabricfrom
mvanhorn:fix/759-cfunction-parse-errors

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Dec 5, 2026

Copy link
Copy Markdown

Why

When a line inside a function file run through /cfunction is written wrongly — for example a command with a stray leading slash, like /csnap ~0.5 ~ ~ — clientcommands answers with brigadier's generic 'unknown or incomplete command' error on the /cfunction command in chat. The message names neither the function file nor the offending line, so players reasonably assume the command they just typed is at fault and go debug the wrong thing. Any player running /cfunction on a function containing a malformed command hits this.

Steps to reproduce:

  1. Create a function file, e.g. test.mcfunction, in the functions folder of the clientcommands config directory.
  2. Put a single command with a stray leading slash in it, e.g. /csnap ~0.5 ~ ~ (the added test's minimal input is a file containing # comment, a blank line, then /unknown, so the bad command sits on line 3).
  3. Run /cfunction test in a world.
  4. Chat shows 'unknown or incomplete command' against the /cfunction command itself, with no function name or line number.

Root cause: executeFunction in src/main/java/net/earthcomputer/clientcommands/features/ClientCommandFunctions.java parses each non-comment line of the function file with brigadier and, when a line does not parse completely, rethrows the raw exception returned by Commands.getParseException(command). That exception carries only brigadier's generic 'unknown or incomplete command' message about the leftover text — the function name and line number are dropped — so the failure reads as if the /cfunction invocation itself were malformed.

What changed

The function file is now read through a size-capped input stream (at most 4 MiB, with a new commands.cfunction.tooLarge message for anything bigger) and decoded explicitly as UTF-8, while a counter tracks the current line number as lines are parsed. A line that fails to parse now throws a new PARSE_EXCEPTION (a Dynamic3CommandExceptionType) combining the function name, the 1-based line number, and brigadier's underlying reason, rendered through the new commands.cfunction.parseError entry, 'Error in function %s on line %s: %s'.

A new ClientCommandFunctionsTest covers the error location for both /unknown and unknown inputs, a command that executes successfully, and the unknown-function path.

Testing

./gradlew --no-daemon test --tests ClientCommandFunctionsTest was invoked to run the new test, but the test command did not run because the credential lockout could not be built, so there is no pass or fail result to report. The new test src/test/java/net/earthcomputer/clientcommands/test/ClientCommandFunctionsTest.java did not run here: no test runner for it was available.

Closes #759

@Earthcomputer Earthcomputer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, if you are going to entirely vibecode a PR, at least use a better clanker that's actually competent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error messages for /cfunction

2 participants