Skip to content

lang: throw, try and catch with one Error type - #2466

Merged
BaseMax merged 9 commits into
mainfrom
lang/throws-try-catch
Oct 28, 2026
Merged

BaseMax merged 9 commits into
mainfrom
lang/throws-try-catch

Conversation

@BaseMax

@BaseMax BaseMax commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Salam had no single way to report an error: out-parameters of many shapes, sentinels, silent zeros, global LastError, and a separate error struct per package. This adds checked errors to the language and one error type to throw.

func parse port(text: str): int throws:
    if text == "": throw Error.New(ErrorKind.InvalidArgument, "empty port") end
    ret text.to_int()
end

func load(text: str): int throws:
    ret try parse port(text) * 2          // passes the error on
end

func main:
    port := try parse port("") catch 8080 // fallback value
    try:
        println load("80"), port
    catch e:
        println e.to_str()
    end
end
  • throws after the return type, throw, try expr, try expr catch fallback, and try: ... catch e: ... end. Persian: خطادار, پرتاب خطا, تلاش, گرفتن خطا.
  • Lowered in sema to a tagged Throws<T> return plus a check after each call, so nothing is unwound and no backend needed new machinery (only continue across a try: block is refused for now). defer runs on every exit. Panics are not caught.
  • Error, ErrorKind and Throws live in core and need no import. std/error is rewritten around them and keeps the retry helpers; its Persian package name becomes خطاها so it no longer hides the type خطا.
  • func main throws prints error: ... to stderr and exits 1.
  • New errors: E139 unmarked throwing call, E140 misplaced try, E141 misplaced or mistyped throw, E142 try with nothing that can throw. raise, except and finally get targeted hints.
  • تلاش is now a keyword, so the Persian names that contained it use کوشش instead (23 std/package names, the position try CSS properties, and the fa tests and examples that used them).
  • try is a keyword too, so the examples and the test that named a helper try call it attempt now.
  • Docs: SKILL.md, AGENTS.md, the MCP hints, learn lessons 15 and 19, the core and error std pages, editor syntaxes and completion.

std still uses the old conventions; moving encoding/json and the rest onto throws (and removing encoding.encerr) comes next, once a release with this compiler is the seed.

Tested on C, LLVM (JIT), the interpreter and JS: features, errors, exec, js and llvm all pass (1095 tests), stdlib and general pass in both languages (1962 tests; net_proxy hit a port collision once and passes on rerun). The rewritten website examples were run in both languages, and prek passes on the changed files.

Persian spellings are تلاش, گرفتن خطا, پرتاب خطا and خطادار. The parser takes throws after a return type, throw as a statement, try as a prefix with an optional catch fallback, and try: ... catch e: ... end blocks.
A throws function returns Throws<T>; every throwing call is hoisted and checked, so no backend needs unwinding. Error, ErrorKind and Throws resolve from core without an import.
The error package's Persian name becomes خطاها so importing it no longer hides the type خطا.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 18:08
@BaseMax
BaseMax requested a review from a team as a code owner October 28, 2026 18:08
@vercel

vercel Bot commented Oct 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
salam Building Building Preview Oct 28, 2026 6:08pm UTC

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 153 files, which is 53 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Check out review usage here.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34e0c07f-4e25-4a59-9a71-f1584fc29b32
Commits

Reviewing files that changed from the base of the PR and between e981ea0 and ff717da.

Files ignored due to path filters: 32
  • tests/en/exec/throws_basic.out is excluded by !**/*.out
  • tests/en/exec/try_in_expr.out is excluded by !**/*.out
  • tests/en/features/main_throws.out is excluded by !**/*.out
  • tests/en/features/throws_basic.out is excluded by !**/*.out
  • tests/en/features/throws_error_shadow.out is excluded by !**/*.out
  • tests/en/features/throws_method_iface.out is excluded by !**/*.out
  • tests/en/features/throws_void.out is excluded by !**/*.out
  • tests/en/features/try_in_expr.out is excluded by !**/*.out
  • tests/en/js/throws_basic.out is excluded by !**/*.out
  • tests/en/llvm/throws_basic.out is excluded by !**/*.out
  • tests/en/stdlib/core_foundations_demo.out is excluded by !**/*.out
  • tests/fa/features/throws_basic.out is excluded by !**/*.out
  • website/content/en/examples/error-guide-format.out is excluded by !**/*.out
  • website/content/en/examples/error-guide-layers.out is excluded by !**/*.out
  • website/content/en/examples/error-guide-retry.out is excluded by !**/*.out
  • website/content/en/examples/error-guide-validate.out is excluded by !**/*.out
  • website/content/en/examples/rules-exit.out is excluded by !**/*.out
  • website/content/en/std-examples/core/core-Error.out is excluded by !**/*.out
  • website/content/en/std-examples/error/error-Kinds.out is excluded by !**/*.out
  • website/content/en/std-examples/error/error-New.out is excluded by !**/*.out
  • website/content/en/std-examples/error/error-RetryPolicy.out is excluded by !**/*.out
  • website/content/en/std-examples/error/error-Wrap.out is excluded by !**/*.out
  • website/content/fa/examples/error-guide-format.out is excluded by !**/*.out
  • website/content/fa/examples/error-guide-layers.out is excluded by !**/*.out
  • website/content/fa/examples/error-guide-retry.out is excluded by !**/*.out
  • website/content/fa/examples/error-guide-validate.out is excluded by !**/*.out
  • website/content/fa/examples/rules-exit.out is excluded by !**/*.out
  • website/content/fa/std-examples/core/core-Error.out is excluded by !**/*.out
  • website/content/fa/std-examples/error/error-Kinds.out is excluded by !**/*.out
  • website/content/fa/std-examples/error/error-New.out is excluded by !**/*.out
  • website/content/fa/std-examples/error/error-RetryPolicy.out is excluded by !**/*.out
  • website/content/fa/std-examples/error/error-Wrap.out is excluded by !**/*.out
Files selected for processing: 153
  • SKILL.md
  • ai/frontend/src/highlight.ts
  • compiler/ast.salam
  • compiler/codegen/codegen_expr.salam
  • compiler/driver/driver_js.salam
  • compiler/langpack.salam
  • compiler/lexer/lexer_ident.salam
  • compiler/parser/parser_cursor.salam
  • compiler/parser/parser_decl.salam
  • compiler/parser/parser_expr.salam
  • compiler/parser/parser_stmt.salam
  • compiler/parser/parser_type.salam
  • compiler/semantic/sema_api.salam
  • compiler/semantic/sema_check_core.salam
  • compiler/semantic/sema_check_fn.salam
  • compiler/semantic/sema_expr.salam
  • compiler/semantic/sema_layout.salam
  • compiler/semantic/sema_lit.salam
  • compiler/semantic/sema_packages.salam
  • compiler/semantic/sema_static.salam
  • compiler/semantic/sema_stmt_lower.salam
  • compiler/semantic/sema_symbol.salam
  • compiler/semantic/sema_throws.salam
  • compiler/semantic/sema_try.salam
  • compiler/semantic/sema_typeres.salam
  • compiler/semantic/semantic.salam
  • compiler/tests_port/ast_test.salam
  • compiler/token.salam
  • docs/CSS_PROPERTIES.md
  • docs/ai/AGENTS.md
  • docs/ai/stdlib-index.json
  • editor/complete.salam
  • extensions/emacs/salam-mode.el
  • extensions/geany/filetypes.Salam.conf
  • extensions/gtksourceview/salam.lang
  • extensions/jetbrains/Salam.xml
  • extensions/kate/salam.xml
  • extensions/micro/salam.yaml
  • extensions/nano/salam.nanorc
  • extensions/notepadpp/salam.xml
  • extensions/sublime/Indentation Rules.tmPreferences
  • extensions/sublime/Salam.sublime-syntax
  • extensions/tools/gen_syntaxes.salam
  • extensions/tree-sitter-salam/keywords.json
  • extensions/tree-sitter-salam/src/keywords.h
  • extensions/vim/ftplugin/salam.vim
  • extensions/vim/indent/salam.vim
  • extensions/vim/syntax/salam.vim
  • extensions/vscode/syntaxes/salam.tmLanguage.json
  • packages/aws/aws.salam
  • packages/aws/s3_creds.salam
  • packages/aws/sqs.salam
  • packages/db/elasticsearch/elasticsearch.salam
  • packages/db/opensearch/opensearch.salam
  • packages/db/opensearch/os_plugins.salam
  • packages/db/typesense/typesense.salam
  • packages/net/socketio/state.salam
  • std/chan/chan.salam
  • std/core/core.salam
  • std/error/error.salam
  • std/layout/style/position.salam
  • std/sync/sync.salam
  • tests/en/errors/throw_outside_throws.salam
  • tests/en/errors/throw_wrong_type.salam
  • tests/en/errors/throws_call_unmarked.salam
  • tests/en/errors/try_in_until_cond.salam
  • tests/en/errors/try_nothing_throws.salam
  • tests/en/errors/try_outside_throws.salam
  • tests/en/exec/throws_basic.salam
  • tests/en/exec/try_in_expr.salam
  • tests/en/features/_throws_shadow_pkg.salam
  • tests/en/features/main_throws.salam
  • tests/en/features/throws_basic.salam
  • tests/en/features/throws_error_shadow.salam
  • tests/en/features/throws_method_iface.salam
  • tests/en/features/throws_void.salam
  • tests/en/features/try_in_expr.salam
  • tests/en/js/throws_basic.salam
  • tests/en/llvm/throws_basic.salam
  • tests/en/stdlib/core_foundations_demo.salam
  • tests/en/stdlib/flag_invalid_numbers.salam
  • tests/fa/db/tslive_ex_connect.salam
  • tests/fa/db/typesense_names.salam
  • tests/fa/features/throws_basic.salam
  • tests/fa/games/jewel-match/game.salam
  • tests/fa/games/shape-puzzle/game.salam
  • tests/fa/games/snake/game.salam
  • tests/fa/general/layout_runtime_router.salam
  • tests/fa/general/web_router.salam
  • tests/fa/general/web_server.salam
  • tests/fa/page/errors/prop_position_try_bad.salam
  • tests/fa/page/errors/prop_position_try_order_bad.salam
  • tests/fa/page/style/prop_position_try.salam
  • tests/fa/page/style/prop_position_try_order.salam
  • tests/fa/stdlib/elasticsearch/client.salam
  • tests/fa/stdlib/elasticsearch/documents.salam
  • tests/fa/stdlib/elasticsearch/resilience.salam
  • tests/fa/stdlib/opensearch/client.salam
  • tests/fa/stdlib/opensearch/documents.salam
  • tests/fa/stdlib/opensearch/ism.salam
  • tools/mcp/mcp_hints.salam
  • tools/mcp/mcp_prompts.salam
  • website/content/en/examples/atomic-guide-first.salam
  • website/content/en/examples/db-postgres-errors.salam
  • website/content/en/examples/encoding-serde-guide-errors.salam
  • website/content/en/examples/error-guide-format.salam
  • website/content/en/examples/error-guide-layers.salam
  • website/content/en/examples/error-guide-retry.salam
  • website/content/en/examples/error-guide-validate.salam
  • website/content/en/examples/net-websocket-auth.salam
  • website/content/en/examples/os-shell-guide-check.salam
  • website/content/en/examples/rules-exit.salam
  • website/content/en/examples/ssh-host-keys.salam
  • website/content/en/learn/15-enums.txt
  • website/content/en/learn/19-rules.txt
  • website/content/en/learn/38-css-more.txt
  • website/content/en/std-examples/core/core-Error.salam
  • website/content/en/std-examples/error/error-Kinds.salam
  • website/content/en/std-examples/error/error-New.salam
  • website/content/en/std-examples/error/error-RetryPolicy.salam
  • website/content/en/std-examples/error/error-Wrap.salam
  • website/content/en/std/01-core.txt
  • website/content/en/std/43-error.txt
  • website/content/fa/examples/atomic-guide-first.salam
  • website/content/fa/examples/chan-guide-shed.salam
  • website/content/fa/examples/error-guide-format.salam
  • website/content/fa/examples/error-guide-layers.salam
  • website/content/fa/examples/error-guide-retry.salam
  • website/content/fa/examples/error-guide-validate.salam
  • website/content/fa/examples/es-errors.salam
  • website/content/fa/examples/net-socketio-chat-bot.salam
  • website/content/fa/examples/opensearch-config.salam
  • website/content/fa/examples/opensearch-errors.salam
  • website/content/fa/examples/rules-exit.salam
  • website/content/fa/examples/time-guide-timeouts.salam
  • website/content/fa/learn/15-enums.txt
  • website/content/fa/learn/19-rules.txt
  • website/content/fa/learn/38-css-more.txt
  • website/content/fa/std-examples/aws/aws-Config.salam
  • website/content/fa/std-examples/chan/chan-Timeout.salam
  • website/content/fa/std-examples/core/core-Error.salam
  • website/content/fa/std-examples/db-opensearch/db-opensearch-Client.salam
  • website/content/fa/std-examples/db-opensearch/db-opensearch-Index.salam
  • website/content/fa/std-examples/db-opensearch/db-opensearch-PutPolicy.salam
  • website/content/fa/std-examples/db-typesense/db-typesense-Client.salam
  • website/content/fa/std-examples/error/error-Kinds.salam
  • website/content/fa/std-examples/error/error-New.salam
  • website/content/fa/std-examples/error/error-RetryPolicy.salam
  • website/content/fa/std-examples/error/error-Wrap.salam
  • website/content/fa/std-examples/net-socketio/net-socketio-Manager.salam
  • website/content/fa/std-examples/sync/sync-RWMutex.salam
  • website/content/fa/std/01-core.txt
  • website/content/fa/std/43-error.txt

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@deepsource-io

deepsource-io Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in e981ea0...ff717da on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Secrets Oct 28, 2026 6:14p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@deepsource-io

deepsource-io Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in e981ea0...ff717da on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Oct 28, 2026 6:14p.m. Review ↗
Secrets Oct 28, 2026 6:14p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 18:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@BaseMax
BaseMax merged commit 614fe2e into main Oct 28, 2026
36 of 45 checks passed
@BaseMax
BaseMax deleted the lang/throws-try-catch branch October 28, 2026 18:13
@github-actions

Copy link
Copy Markdown
Contributor

Super-linter summary

Language Validation result
CHECKOV Pass ✅
CLANG_FORMAT Pass ✅
EDITORCONFIG Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
JSCPD Pass ✅
JSON Pass ✅
MARKDOWN Pass ✅
MARKDOWN_PRETTIER Pass ✅
NATURAL_LANGUAGE Pass ✅
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
XML Pass ✅
YAML Pass ✅
YAML_PRETTIER Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter
Super-linter revision: 2da136927bd4a73596db63044b504547c62cb854
Super-linter version: 9.0.0

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

Labels

documentation Improvements or additions to documentation repo tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants