Repository navigation
Capture errors in LayerInfo::write's parallel compress loop - #224
Merged
EmilDohne merged 1 commit intoNov 1, 2026
Merged
Conversation
An exception escaping a std::execution::par callable calls std::terminate, so any error raised while compressing a layer's channels (a codec or allocation failure, or PSAPI_LOG_ERROR's throw for an unsupported bit depth) ended the host process instead of reaching the caller. Capture the first exception and rethrow it once the loop has finished, before any layer record is written. Behaviour on success is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Thanks for the fix @imdanberry, LGTM I've merged it now. I'm working on some performance improvements and will create a new release once that is done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LayerInfo::writecompresses each layer's channels insidestd::for_each(std::execution::par, …). An exception escaping a callablerun under
std::execution::parcallsstd::terminate([algorithms.parallel.exceptions]),so any error raised while compressing — a codec failure, an allocation
failure, or
PSAPI_LOG_ERROR's throw for an unsupported bit depth — endsthe host process instead of reaching the caller's
catch.This change wraps the per-layer body in a
try/catch (...), records thefirst exception under a mutex, and rethrows it once the loop has finished,
before any layer record is written. Behaviour on success is unchanged: the
same work runs in the same loop, and the output is byte-identical.
LayerInfo::read's parallel channel loop has the same exposure — atruncated or corrupt channel throws inside it — and the same capture fixes
it there. Happy to send that as a follow-up.
Verification
Against a fresh clone of
masterat 51bb741, with only this change applied:PhotoshopAPI/src/PhotoshopFile/LayerAndMaskInformation.cppcompiles with AppleClang on arm64 (-std=gnu++20, the flags of our own build), both normally and with-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES. No includes were added: the translation unit gets<mutex>fromUtil/Logger.hand<exception>from nlohmann/json'sdetail/exceptions.hpp(via compressed-image'schannel.h), both explicit includes.In our fork the same change has been in a full rebuild (macOS arm64 / x86_64 and iOS arm64) and our test suite, where a test throws from inside this loop at every layer and requires a clean exception at the call site with the process still running.
Reporter context
Found while adding per-layer cancellation to exports in Flattener (an
iPad / Mac comics flatting app built on PhotoshopAPI): a cancel thrown from
that loop would have terminated the app, and so, today, does any
compression error that throws there.
🤖 Generated with Claude Code