Skip to content

feat(#5166): safe navigation and on-error handling#5176

Open
akrzywicki wants to merge 1 commit into
objectionary:masterfrom
akrzywicki:feat/#5166/error-handling
Open

feat(#5166): safe navigation and on-error handling#5176
akrzywicki wants to merge 1 commit into
objectionary:masterfrom
akrzywicki:feat/#5166/error-handling

Conversation

@akrzywicki

Copy link
Copy Markdown

Summary

  • Add ?. safe navigation: parser @safe, transpile via DataizedSafe.take, runtime catches EOerror.ExError and returns the error object as a value.
  • Add book? on-error replacement: parser @on-error, canonical lowering in expand-on-error.xsl to Φ.on-error application.
  • Replace legacy try with on-error (on-error.eo, EOonError), migrate stdlib .eo call sites, remove try.eo / EOtry.

Known gaps / follow-ups

  • Vertical handler under book? > [e] >> (issue example with tt.sprintf on following lines) is not parsed yet; documented in PARSER_SPEC.md as a follow-up. Desugar covers the only-phi handler shape covered by eo-syntax packs.
  • Data.ToPhi / ExReadOnly regression after pure objects #5165 (PhApplication / PhOnce): constructing Data.ToPhi while an AtOnce(AtComposite) attribute is being read can throw ExReadOnly. New JUnit tests avoid ToPhi in attribute getters; some existing tests (e.g. EOerrorTest) may still fail on current master lineage until that interaction is fixed upstream or in a separate PR.

Test plan

  • mvn test -pl eo-parser -Dtest=EoSyntaxTest
  • mvn test -pl eo-parser -Dtest=EoTest#parsesSafeNavigationInChain,EoTest#parsesOnErrorOnlyPhi
  • mvn test -pl eo-runtime -Dtest=DataizedSafeTest,EOonErrorTest
  • mvn test -pl eo-maven-plugin -Dtest=MjTranspileTest (includes safe-navigation pack)
  • rm -rf ~/.eo/transpiled && mvn clean install -Pqulice (maintainer / CI; may surface Data.ToPhi failures unrelated to this diff)

Fixes #5166

@github-actions

github-actions Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

🚀 Performance Analysis

All benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information.

Click to see the detailed report
Test Base Score PR Score Change % Change Unit Mode
benchmarks.XmirBench.xmirToEO 12648.013 12618.925 -29.087 -0.23% ms/op Average Time

✅ Performance gain: benchmarks.XmirBench.xmirToEO is faster by 29.087 ms/op (0.23%)

@yegor256

Copy link
Copy Markdown
Member

@akrzywicki Thanks for your contribution, we appreciate it! Before we can merge this pull request, we need to see all CI workflows pass without errors. We can't merge the pull request into the master branch unless all workflows are green. Try to fix them, also paying attention to code style issues.

@akrzywicki
akrzywicki force-pushed the feat/#5166/error-handling branch 5 times, most recently from f2baaca to 6960fdd Compare May 31, 2026 18:36
@yegor256
yegor256 requested a review from maxonfjvipon June 2, 2026 05:52
@yegor256

yegor256 commented Jun 2, 2026

Copy link
Copy Markdown
Member

@maxonfjvipon WDYT?

@maxonfjvipon maxonfjvipon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@akrzywicki not enough tests with longer dispatch/application chains in runtime and in parser

"Couldn't create a Win32 socket, WSA error code: %d"
* err.code
try
on-error

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@akrzywicki just replacing try with new object is not what we wanted to achieve, I don't think we need some extra object to replace try at all

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@maxonfjvipon Thanks for the review.

I see, #5166 is about the new error-handling model (book?, ?., desugar), not a straight try -> on-error rename across stdlib.

In this PR I used on-error mainly where the new pipeline needs it (desugar target and dataized). The explicit on-error blocks in stdlib were my attempt to remove legacy try step by step - if that is not the direction you want, I will adjust the approach.

I can revert the stdlib migration (and bring try back there if needed) and keep on-error only as the desugar/runtime target plus dataized. Or follow another pattern you prefer.

What would you like me to do?

<xsl:function name="eo:safe-method">
<xsl:param name="base"/>
<xsl:param name="mtd"/>
<xsl:text>DataizedSafe.take(</xsl:text>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@akrzywicki this safe dataization should not be exposed in the generated code, we've already have PhSafe

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed: generated code now uses PhSafe.takeNav instead of DataizedSafe.take. DataizedSafe remains internal for tests and dataized() helper.

@akrzywicki

Copy link
Copy Markdown
Author

@maxonfjvipon Re: longer dispatch/application chains - added:

  • Parser: eo-syntax/safe-navigation-long-chain.yaml, EoTest.parsesSafeNavigationLongChain (book?.mid?.inner.title)
  • Transpile: transpile-packs/safe-navigation-long-chain.yaml (root?.a.b.c - rolled chain wraps new PhSafe(...) per current XSL)
  • Runtime: PhSafeTest chain tests for PhSafe.takeNav (3-step, error on middle link)

Happy to extend if you want more cases.

@akrzywicki
akrzywicki force-pushed the feat/#5166/error-handling branch from 6960fdd to 6c2a620 Compare June 2, 2026 16:52
Replace legacy try with on-error, desugar book? to Φ.on-error, and emit
DataizedSafe for ?. at transpile time so dataization errors become values.
@akrzywicki
akrzywicki force-pushed the feat/#5166/error-handling branch from 6c2a620 to dae0eec Compare June 2, 2026 17:09
@sonarqubecloud

sonarqubecloud Bot commented Jun 2, 2026

Copy link
Copy Markdown

@yegor256

Copy link
Copy Markdown
Member

@akrzywicki merge conflicts here

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get rid of exceptions and try/catch, new style of error handling

3 participants