Repository navigation
knowledge(error-handling): a bare [TryFunction] call propagates its error - #211
Conversation
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Reviewed draft head da5a28819eb26dc786ff364ed74f0f85cb5aa940. The Error Handling correction is accurate, and the new good/bad controls correctly distinguish intended propagation from a dead last-error branch. One tightly coupled cross-domain contradiction remains in the events article this PR also edits.
microsoft/knowledge/events/avoid-raising-events-inside-try-functions.md:18,24 still unconditionally says raising an event inside a TryFunction body is an anti-pattern and that subscriber errors are caught/discarded. If an attributed publisher helper is invoked as a bare TryPublish();, a subscriber error propagates normally: no try boundary is activated. Qualifying only the opening Description sentence does not fix the normative Best Practice/Anti Pattern sections; al-events-review explicitly evaluates those sections and emits a major finding for a match, independently of the new Error Handling clarification.
Please qualify those normative sections by the actual consumed-result try invocation, explicitly exempt the intentionally bare publisher path, and include that path as a clean control. This requires no composed-review contract expansion or generic leaf-agent suppression change. Exact-head local validators pass; the gap is semantic rather than structural.
|
Kilian Seizinger (@pri-kise), let's complete this one 😊 Anything you need from me? |
…rror The review agent repeatedly flagged bare calls to [TryFunction] procedures (e.g. the System Application "Xml Validation" Try* APIs) as defects, including claims that the failure is "silently swallowed". A bare call is an ordinary call: the error propagates as usual. - Add negative knowledge bare-tryfunction-call-propagates-errors.md. - Narrow ignored-tryfunction-return-disables-try-semantics to code that visibly expects the failure to be caught; the bad sample now shows that in code, and the good sample includes an intentional bare call as the clean control. - Qualify "TryFunction catches all errors" in the events article and the "must be consumed" wording in the performance article. - Error-handling leaf worklists both articles for bare [TryFunction] calls and requires the same evidence before flagging. - Add the three paired articles to the evaluation overrides.
… call sites Address review on microsoft#211: the Best Practice and Anti Pattern of avoid-raising-events-inside-try-functions now apply only when a call site consumes the TryFunction's Boolean result. A publisher helper that is only invoked as a bare statement activates no try boundary, so subscriber errors propagate; it is explicitly exempt and the good sample adds it as a clean control.
da5a288 to
609ef4d
Compare
|
Thanks Jesper Schulz-Wedde (@JesperSchulz)! Rebased onto current
Local validators pass ( |
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Thanks, this resolves the remaining issue. The events guidance now distinguishes calls that catch errors from bare calls that intentionally let them propagate, and the new example covers the bare publisher case.
90540bb
into
microsoft:main
Why this correction is needed
The AL review agent keeps flagging bare calls to
[TryFunction]procedures as defects. On microsoft/BCApps#8429 it commented three times on the same lines, which call the System ApplicationXml Validationtry-APIs without using their return value:ignored-tryfunction-return-disables-try-semantics.mdAll three are wrong, and the third contradicts the first two. The flagged procedure's doc comment says it "Raises an error describing the first schema violation found", and the bare calls do exactly that. The author explained this twice in the PR (1, 2).
Valid pattern: calling a
[TryFunction]as a standalone statement when the error should propagate. Without the return value, it is an ordinary call.Incorrect findings prevented:
if not Try...() then Error(GetLastErrorText()), which replaces the original error and can move customer content into the message (seeprivacy/getlasterrortext-customer-content-in-errors.md)Root causes in the corpus
ignored-tryfunction-return-disables-try-semantics.mddescribes the platform correctly. But its title and Best Practice read as "always consume the result", and only the Anti Pattern carries the real condition ("…and assuming the attribute suppresses its errors").[TryFunction]with an ignored result.performance/use-tryfunction-for-error-catching-not-rollback.mdsaid the result "must be consumed".events/avoid-raising-events-inside-try-functions.mdsaid "A TryFunction catches all errors" without qualification.What this changes
error-handling/bare-tryfunction-call-propagates-errors.md. A bare call propagates. Do not report it as swallowed, and do not ask for capture-and-re-raise. ATryname prefix does not establish[TryFunction], so resolve the declaration.ignored-tryfunction-return-disables-try-semantics.md: the Anti Pattern now requires code that visibly expects the failure to be caught: a laterGetLastErrorText/GetLastErrorCode/GetLastErrorObjectcheck, a failure branch or result, or a loop meant to continue past failures. A bare call without such handling is explicitly not this anti-pattern..bad.alnow shows the mistake in code: a bare call followed by aGetLastErrorTextcheck that can never see the error..good.aladds an intentional bare call as the clean control.al-error-handling-review.md: worklists both articles for bare[TryFunction]calls, and requires the same evidence before flagging.evaluation/review-fixtures.json: addsignored-tryfunction-return-disables-try-semanticsto the error-handling override. It also addsavoid-raising-events-inside-try-functionsanduse-tryfunction-for-error-catching-not-rollback, because editing their text triggers the changed-article coverage gate.Evidence
Xml Validationcodeunit: everyTry*procedure is declared[TryFunction].BC versions: the new article is
[all], because this is long-standing platform behaviour. The existing article keeps[13..].Domain:
error-handling. The concern is how errors move through a try-method call site, and that domain already owns the paired rule.Not addressed here
The Security-domain comment (r3958572924) came from a leaf agent finding. Leaf retrieval is domain-scoped, so the Security leaf never loads this error-handling article.
al-code-review.mdalso exempts leaf agent findings from the cross-leaf contradiction check, andValidate-FindingsReport.ps1requires every leaf finding to appear in the rollup (SUPER_FINDING_MISSING). Suppressing such a finding needs a contract and validator change. I'd propose that separately rather than widen this PR.Validation
Test-ReviewFixtures.ps1with the changed-paths file: passed, 234 cases.Test-ReviewContract.ps1: passed.Test-KnowledgeRetrieval.ps1: passed, 403 articles and 691 samples round-tripped.Build-KnowledgeIndex.ps1/Build-SkillIndex.ps1: built cleanly.validate_frontmatter.pywas not run locally (no Python on this machine). I checked its rules by hand: six frontmatter keys,## Description, no fenced code, under 100 lines, sample links present.