Repository navigation
fix(ts): name the hook and event in hook timeout errors - #1140
Conversation
A timed-out hook reported `hook hook. timed out after Nms` because the name came from opts.hook, which callers do not pass, and the event was dropped. Name each hook as Class.event and match Python's TimeoutError wording. Skip the timer for a synchronous result, and drop the unused timeout locals in sync dispatch. Co-authored-by: Nithilan Kumaran <sathariels@users.noreply.github.com>
|
Merged. Verified: 875 tests across 35 files pass, Three separate defects fixed here, and the message format is the least of them. The The The non-thenable early return is the real behaviour change: a synchronous hook already finished, so arming a timer for it was pure overhead, and
|
Summary
Follow-up to the timeout path in
laya-ts/src/hooks.tsthat #1056 got parsing again. In the merge comment on that PR, Nandha keptrunWithTimeoutasPromise<void>and said returning the hook's value would be a contract change of its own. Nothing in the TypeScript runtime reads a hook's return value, so this leaves that signature alone.The bug that is still on main is the message.
operationNamewas built fromopts.hook, whichagent.tsnever passes, and it dropped the event, so a timeout came out ashook hook. timed out after 50ms. It now names the hook that actually ran,Class.event, and uses the same wording as Python and the Java port:laya: hook SlowHook.onPredictStart exceeded 0.05s, on anErrorwhosenameisTimeoutError.What changed
dispatchAsyncbuilds the name per hook as${hook.constructor.name}.${event}instead of readingopts.hook.%gprints them (0.05,1, not1.0), matchinglaya/hooks.pyandHooks.secondsin the Java SDK.clearTimeoutruns on the way out either way.dispatchno longer computestimeoutMsandoperationNameand then ignores them. It still does not wait, and it still does not apply a timeout.PredictBatchOptionsandpredictBatchdocblocks now saysetDefaultHooksdefaults, then installed hooks, then this call's hooks, which is whatcomposeHooksalready does (laya/router.pyaround thepredict_batchcomposition comment).Tests
New cases in
laya-ts/tests/hooks.test.ts, under fake timers:TimeoutErrorsetTimeouthooksRaise: falsewarns with that same message and the call still returnshooksTimeoutoverrides the agent default in both directionsOn current main, before this change, four of those five failed. The warning was
laya: hook SlowHook.onPredictStart failed: Error: hook hook. timed out after 50ms, the thrown error's name wasError, and the sync hook still armed a 50ms timer. The "clears the timer" case already passed, becauserunWithTimeoutcleared infinally.npm test -- --runinlaya-ts: typecheck plus 35 files, 875 tests, all passed.npx tsc --noEmitis clean. There is no TypeScript lint script; CONTRIBUTING's ruff gate is Python, and this commit does not touch it. No changelog entry: the repo convention for this tree is the commit, andlaya-tshas no changelog.