Skip to content

fix: make the unknown target reason warning informative and rate-limited - #605

Merged
pisaiah merged 1 commit into
CardboardPowered:ver/26.1from
KostiaFed:fix/unknown-target-reason-log-spam
Aug 25, 2026
Merged

fix: make the unknown target reason warning informative and rate-limited#605
pisaiah merged 1 commit into
CardboardPowered:ver/26.1from
KostiaFed:fix/unknown-target-reason-log-spam

Conversation

@KostiaFed

@KostiaFed KostiaFed commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Problem

Mob#setTarget calls that reach cardboard$setTarget without a mapped TargetReason log:

[01:05:38] [Server thread/WARN]: Unknown target reason, please report on the issue tracker

with a bare new Exception() stack trace. This can happen every tick for every mob, so the log fills with millions of identical lines and the stack traces make it worse rather than actionable.

Change

  • Moved the warning into cardboard$warnUnknownTargetReason, which reports the mob type, uuid, world, block position, old target and new target, plus the top 4 caller frames (our own mixin frames skipped).
  • Rate limiting: each distinct (mob type, call site) pair is reported only once per server run, so a genuinely new code path is still surfaced while the per-tick spam is gone.

Example output:

Unknown EntityTargetEvent.TargetReason for minecraft:zombie (uuid=..., world=minecraft:overworld, pos=12, 64, -30), old target=none, new target=minecraft:player/...
  called from:
    net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal.start(NearestAttackableTargetGoal.java:123)
    ...
  Only the first occurrence per mob type and call site is logged. Please report this on the Cardboard issue tracker.

Note (not addressed here)

setTargetCraftBukkit passes the current target field instead of the livingEntity argument to cardboard$setTarget, so the incoming target never reaches the event. That looks like a separate bug and is left untouched, since fixing it changes event behaviour.

Testing

./gradlew compileJava passes.

The warning fired with a bare stack trace on every setTarget call that had
no mapped TargetReason, which can happen every tick for every mob and buries
the log in identical lines.

Log the mob type, uuid, world, position, old and new target plus the top
caller frames instead, and report each (mob type, call site) pair only once
per server run so new code paths are still surfaced without the spam.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pisaiah
pisaiah merged commit d24d071 into CardboardPowered:ver/26.1 Aug 25, 2026
1 check passed
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.

2 participants