Skip to content

Add SysError/WinError constructors that take a HintFmt-producing function#15359

Merged
Ericson2314 merged 1 commit intomasterfrom
error-create-from-lambda
Feb 27, 2026
Merged

Add SysError/WinError constructors that take a HintFmt-producing function#15359
Ericson2314 merged 1 commit intomasterfrom
error-create-from-lambda

Conversation

@Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Feb 26, 2026

Motivation

This allows capturing errno/GetLastError() before constructing the error message. Useful when the error message construction itself might clobber the error code (e.g., calling descriptorToPath()).

Also fix the Windows build

Context

Usage:

throw NativeSysError([&] { return HintFmt("msg %s", foo()); });

The error code is captured when the exception is constructed, then the lambda is called to produce the HintFmt.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@Ericson2314 Ericson2314 force-pushed the error-create-from-lambda branch 2 times, most recently from 89835b2 to a7891c9 Compare February 27, 2026 00:02
@Ericson2314 Ericson2314 force-pushed the error-create-from-lambda branch from a7891c9 to 23cc9e0 Compare February 27, 2026 00:08
…g function

This allows capturing the current value/result of
`errno`/`GetLastError()` before constructing the error message. Useful
when the error message construction itself might clobber the error code
(e.g., calling `descriptorToPath()`).

Usage:
```
throw NativeSysError([&] { return HintFmt("msg %s", foo()); });
```

The error code is captured when the exception is constructed, then the
lambda is called to produce the `HintFmt`.

Also fix the Windows build
@Ericson2314 Ericson2314 force-pushed the error-create-from-lambda branch from 23cc9e0 to 718e4db Compare February 27, 2026 01:16
@Ericson2314 Ericson2314 added this pull request to the merge queue Feb 27, 2026
Merged via the queue into master with commit 3b003b7 Feb 27, 2026
19 checks passed
@Ericson2314 Ericson2314 deleted the error-create-from-lambda branch February 27, 2026 02:54
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.

2 participants