Skip to content

Catch errors in server loop and exit more gracefully#154

Merged
mjambon merged 1 commit intomainfrom
10-25-catch_errors_in_server_loop_and_exit_more_gracefully
Oct 26, 2025
Merged

Catch errors in server loop and exit more gracefully#154
mjambon merged 1 commit intomainfrom
10-25-catch_errors_in_server_loop_and_exit_more_gracefully

Conversation

@mjambon
Copy link
Member

@mjambon mjambon commented Oct 25, 2025

Catch and report exceptions due to internal errors arising when printing test statuses in the scheduler's loop and other operations that aren't supposed to fail. This tries to close the workers cleanly, saving them from a confusing death by broken pipe.

Test plan: add a if Random.int 5 = 0 then failwith "debugging" |> ignore;​ at the beginning of the print_status​ function to simulate a real error. Then run ./test​. Change the argument to Random.int​ to trigger the error in other contexts.

PR checklist:

  • Purpose of the code is evident to future readers
  • Tests are included or a PR comment includes a reproducible test plan
  • Documentation is up-to-date
  • A changelog entry was added to CHANGES.md for any user-facing change

Check out CONTRIBUTING.md for more details.

Copy link
Member Author

mjambon commented Oct 25, 2025

@mjambon mjambon marked this pull request as ready for review October 25, 2025 21:30
@mjambon mjambon force-pushed the 10-25-catch_errors_in_server_loop_and_exit_more_gracefully branch from 261547c to 418c6f4 Compare October 25, 2025 21:40
Copy link
Member Author

mjambon commented Oct 26, 2025

Merge activity

  • Oct 26, 5:17 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 26, 5:18 AM UTC: Graphite rebased this pull request as part of a merge.
  • Oct 26, 5:19 AM UTC: @mjambon merged this pull request with Graphite.

@mjambon mjambon changed the base branch from 10-25-rewrap_test_function_for_more_clarity_and_better_error_handling to graphite-base/154 October 26, 2025 05:17
@mjambon mjambon changed the base branch from graphite-base/154 to main October 26, 2025 05:17
@mjambon mjambon force-pushed the 10-25-catch_errors_in_server_loop_and_exit_more_gracefully branch from 418c6f4 to 73c4a01 Compare October 26, 2025 05:18
@mjambon mjambon merged commit fdff0ca into main Oct 26, 2025
4 of 7 checks passed
@mjambon mjambon deleted the 10-25-catch_errors_in_server_loop_and_exit_more_gracefully branch October 26, 2025 05:19
mjambon added a commit to mjambon/opam-repository that referenced this pull request Jan 17, 2026
CHANGES:

* Add support for checked output files
  ([semgrep/testo#134](semgrep/testo#134)).
* Add an option `inline_logs` to create a test for which logs are
  always or never shown inline
  ([semgrep/testo#142](semgrep/testo#142)).
* Add a command-line option `--max-inline-log-bytes` to limit the size
  of unchecked test output (logs) shown inline when reporting the
  status of a test. The default limit is 1MB
  ([semgrep/testo#144](semgrep/testo#144)).
* Improve internal error handling ([semgrep/testo#153](semgrep/testo#153), [semgrep/testo#154](semgrep/testo#154)).
* Add support for boolean selection queries on test tags, extending
  `-t` ([semgrep/testo#5](semgrep/testo#5)). The query
  language keywords `and`, `or`, `not`, `all`, and `none` can no
  longer be used as tag names.
* New experimental submodule [Testo.Lazy_with_output] module for lazy
  computations that cache standard output and error output in addition
  to the computation's result or exception.
  This allows for sharing context between tests running in the same
  worker process. It saves unnecessary computations while providing
  the same logs for each test sharing this context
  ([semgrep/testo#156](semgrep/testo#156)).
* Report and highlight differences in Unix vs. Windows line endings as
  well as missing trailing newlines
  ([semgrep/testo#163](semgrep/testo#163).
* Testo's snapshot files are now open in text mode for Windows-Unix
  compatibility. When reading files on Windows, CRLFs are converted to
  LFs. When writing, LFs are converted to CRLFs. Git or equivalent
  must be set up to convert line endings appropriately when moving
  files across platforms
  ([semgrep/testo#165](semgrep/testo#165)).
* A series of functions for reading and writing files has been deprecated
  and renamed to hint that we're reading or writing in text mode on
  Windows. These functions are `write_file`, `read_file`, `map_file`,
  `copy_file`, and `with_temp_file`. The new names are
  `write_text_file`, `read_text_file`, etc.
  ([semgrep/testo#165](semgrep/testo#165)).
* Testo's own test suite now passes successfully on Windows.
* Add a `-C`/`--chdir` option to set the current working directory
  ([semgrep/testo#167](semgrep/testo#167)).
* Add support for a `Testo.check` function and testables, replicating the
  similar functionality found in Alcotest. This makes it practical to
  write tests that don't depend on the Alcotest library
  ([semgrep/testo#169](semgrep/testo#169)).
* Show current working directory (cwd) when reporting missing files
  if one of the paths is relative
  ([semgrep/testo#170](semgrep/testo#170).
* Rename the `broken` option of `Testo.create` and `Testo.update` to
  `flaky`
  ([semgrep/testo#172](semgrep/testo#172)).
mjambon added a commit to mjambon/opam-repository that referenced this pull request Jan 17, 2026
CHANGES:

* Add support for checked output files
  ([semgrep/testo#134](semgrep/testo#134)).
* Add an option `inline_logs` to create a test for which logs are
  always or never shown inline
  ([semgrep/testo#142](semgrep/testo#142)).
* Add a command-line option `--max-inline-log-bytes` to limit the size
  of unchecked test output (logs) shown inline when reporting the
  status of a test. The default limit is 1MB
  ([semgrep/testo#144](semgrep/testo#144)).
* Improve internal error handling ([semgrep/testo#153](semgrep/testo#153), [semgrep/testo#154](semgrep/testo#154)).
* Add support for boolean selection queries on test tags, extending
  `-t` ([semgrep/testo#5](semgrep/testo#5)). The query
  language keywords `and`, `or`, `not`, `all`, and `none` can no
  longer be used as tag names.
* New experimental submodule [Testo.Lazy_with_output] module for lazy
  computations that cache standard output and error output in addition
  to the computation's result or exception.
  This allows for sharing context between tests running in the same
  worker process. It saves unnecessary computations while providing
  the same logs for each test sharing this context
  ([semgrep/testo#156](semgrep/testo#156)).
* Report and highlight differences in Unix vs. Windows line endings as
  well as missing trailing newlines
  ([semgrep/testo#163](semgrep/testo#163)).
* Testo's snapshot files are now open in text mode for Windows-Unix
  compatibility. When reading files on Windows, CRLFs are converted to
  LFs. When writing, LFs are converted to CRLFs. Git or equivalent
  must be set up to convert line endings appropriately when moving
  files across platforms
  ([semgrep/testo#165](semgrep/testo#165)).
* A series of functions for reading and writing files has been deprecated
  and renamed to hint that we're reading or writing in text mode on
  Windows. These functions are `write_file`, `read_file`, `map_file`,
  `copy_file`, and `with_temp_file`. The new names are
  `write_text_file`, `read_text_file`, etc.
  ([semgrep/testo#165](semgrep/testo#165)).
* Testo's own test suite now passes successfully on Windows.
* Add a `-C`/`--chdir` option to set the current working directory
  ([semgrep/testo#167](semgrep/testo#167)).
* Add support for a `Testo.check` function and testables, replicating the
  similar functionality found in Alcotest. This makes it practical to
  write tests that don't depend on the Alcotest library
  ([semgrep/testo#169](semgrep/testo#169)).
* Show current working directory (cwd) when reporting missing files
  if one of the paths is relative
  ([semgrep/testo#170](semgrep/testo#170)).
* Rename the `broken` option of `Testo.create` and `Testo.update` to
  `flaky`
  ([semgrep/testo#172](semgrep/testo#172)).
mjambon added a commit to mjambon/opam-repository that referenced this pull request Jan 18, 2026
CHANGES:

- Add support for checked output files ([\semgrep/testo#134](semgrep/testo#134)).
- Add an option `inline_logs` to create a test for which logs are always or never shown inline ([\semgrep/testo#142](semgrep/testo#142)).
- Add a command-line option `--max-inline-log-bytes` to limit the size of unchecked test output (logs) shown inline when reporting the status of a test. The default limit is 1MB ([\semgrep/testo#144](semgrep/testo#144)).
- Improve internal error handling ([\semgrep/testo#153](semgrep/testo#153), [\semgrep/testo#154](semgrep/testo#154)).
- Add support for boolean selection queries on test tags, extending `-t` ([\semgrep/testo#5](semgrep/testo#5)). The query language keywords `and`, `or`, `not`, `all`, and `none` can no longer be used as tag names.
- New experimental submodule \[Testo.Lazy_with_output\] module for lazy computations that cache standard output and error output in addition to the computation’s result or exception. This allows for sharing context between tests running in the same worker process. It saves unnecessary computations while providing the same logs for each test sharing this context ([\semgrep/testo#156](semgrep/testo#156)).
- Report and highlight differences in Unix vs. Windows line endings as well as missing trailing newlines ([\semgrep/testo#163](semgrep/testo#163)).
- Testo’s snapshot files are now open in text mode for Windows-Unix compatibility. When reading files on Windows, CRLFs are converted to LFs. When writing, LFs are converted to CRLFs. Git or equivalent must be set up to convert line endings appropriately when moving files across platforms ([\semgrep/testo#165](semgrep/testo#165)).
- A series of functions for reading and writing files has been deprecated and renamed to hint that we’re reading or writing in text mode on Windows. These functions are `write_file`, `read_file`, `map_file`, `copy_file`, and `with_temp_file`. The new names are `write_text_file`, `read_text_file`, etc. ([\semgrep/testo#165](semgrep/testo#165)).
- Testo’s own test suite now passes successfully on Windows.
- Add a `-C`/`--chdir` option to set the current working directory ([\semgrep/testo#167](semgrep/testo#167)).
- Add support for a `Testo.check` function and testables, replicating the similar functionality found in Alcotest. This makes it practical to write tests that don’t depend on the Alcotest library ([\semgrep/testo#169](semgrep/testo#169)).
- Show current working directory (cwd) when reporting missing files if one of the paths is relative ([\semgrep/testo#170](semgrep/testo#170)).
- Rename the `broken` option of `Testo.create` and `Testo.update` to `flaky` ([\semgrep/testo#172](semgrep/testo#172)).
mjambon added a commit to mjambon/opam-repository that referenced this pull request Jan 18, 2026
CHANGES:

- Add support for checked output files ([semgrep/testo#134](semgrep/testo#134)).
- Add an option `inline_logs` to create a test for which logs are always or never shown inline ([semgrep/testo#142](semgrep/testo#142)).
- Add a command-line option `--max-inline-log-bytes` to limit the size of unchecked test output (logs) shown inline when reporting the status of a test. The default limit is 1MB ([semgrep/testo#144](semgrep/testo#144)).
- Improve internal error handling ([semgrep/testo#153](semgrep/testo#153), [semgrep/testo#154](semgrep/testo#154)).
- Add support for boolean selection queries on test tags, extending `-t` ([semgrep/testo#5](semgrep/testo#5)). The query language keywords `and`, `or`, `not`, `all`, and `none` can no longer be used as tag names.
- New experimental submodule \[Testo.Lazy_with_output\] module for lazy computations that cache standard output and error output in addition to the computation’s result or exception. This allows for sharing context between tests running in the same worker process. It saves unnecessary computations while providing the same logs for each test sharing this context ([semgrep/testo#156](semgrep/testo#156)).
- Report and highlight differences in Unix vs. Windows line endings as well as missing trailing newlines ([semgrep/testo#163](semgrep/testo#163)).
- Testo’s snapshot files are now open in text mode for Windows-Unix compatibility. When reading files on Windows, CRLFs are converted to LFs. When writing, LFs are converted to CRLFs. Git or equivalent must be set up to convert line endings appropriately when moving files across platforms ([semgrep/testo#165](semgrep/testo#165)).
- A series of functions for reading and writing files has been deprecated and renamed to hint that we’re reading or writing in text mode on Windows. These functions are `write_file`, `read_file`, `map_file`, `copy_file`, and `with_temp_file`. The new names are `write_text_file`, `read_text_file`, etc. ([semgrep/testo#165](semgrep/testo#165)).
- Testo’s own test suite now passes successfully on Windows.
- Add a `-C`/`--chdir` option to set the current working directory ([semgrep/testo#167](semgrep/testo#167)).
- Add support for a `Testo.check` function and testables, replicating the similar functionality found in Alcotest. This makes it practical to write tests that don’t depend on the Alcotest library ([semgrep/testo#169](semgrep/testo#169)).
- Show current working directory (cwd) when reporting missing files if one of the paths is relative ([semgrep/testo#170](semgrep/testo#170)).
- Rename the `broken` option of `Testo.create` and `Testo.update` to `flaky` ([semgrep/testo#172](semgrep/testo#172)).
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.

1 participant