fix(libSceNpTrophy2): return errors instead of throwing across the C ABI #15019

Merged
MarcZX10 merged 4 commits from upstream-pr/15019 into main 2026-11-03 05:13:16 +00:00
MarcZX10 commented 2026-11-02 10:34:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T10:34:44Z.


What

Three extern "C" trophy exports let C++ exceptions cross the C ABI into the title. Two are real defects and are fixed here; the third was checked and dropped.

  • NpTrophy2RecordUnlock with a negative trophy id reached TrophyStore::Unlock, which throws std::invalid_argument. With no trophy package loaded the posted-unlock check is skipped, so this was reachable without trophy data. Fix: refuse negative ids in the export and return false (commit e65aec5, test 95ac706).
  • NpTrophy2RemoveUnlockListener threw std::invalid_argument for an id that is not registered. The export is void, so there is no status to return. Fix: an unknown id is a no-op (commit ad7a9b9, test 81de924). The existing store test pinned the throw; it now checks that the second removal does not throw.

Dropped: TitleTrophies.cpp file_size may throw filesystem_error. filesystem_error derives from std::system_error, which derives from std::runtime_error, and loadTitleFile catches std::runtime_error, so the exception does not escape.

Commits:

  • e65aec5 fix(libSceNpTrophy2): return false for a negative trophy id instead of throwing
  • 95ac706 test(libSceNpTrophy2): cover a negative trophy id in NpTrophy2RecordUnlock
  • ad7a9b9 fix(libSceNpTrophy2): ignore an unknown listener id in RemoveUnlockListener
  • 81de924 test(libSceNpTrophy2): expect no throw when a listener is removed twice

Tested

Linux archive build on this host (kernel 6.1), run through the shared build lock with run_tests.sh '^np_trophy2_store$' np_trophy2_store_tests: BUILD-EXIT 0, 1/1 Test #2459: np_trophy2_store ... Passed, 100% passed.
python3 tools/check_conventions.py --base upstream/main clean; git diff --check upstream/main clean.
Not run against the unfixed code (no negative control was executed). Not run: guest_nptrophy2, Windows, macOS, a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5118875354 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15019). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T10:34:44Z. --- ### What Three `extern "C"` trophy exports let C++ exceptions cross the C ABI into the title. Two are real defects and are fixed here; the third was checked and dropped. - `NpTrophy2RecordUnlock` with a negative trophy id reached `TrophyStore::Unlock`, which throws `std::invalid_argument`. With no trophy package loaded the posted-unlock check is skipped, so this was reachable without trophy data. Fix: refuse negative ids in the export and return `false` (commit e65aec5, test 95ac706). - `NpTrophy2RemoveUnlockListener` threw `std::invalid_argument` for an id that is not registered. The export is `void`, so there is no status to return. Fix: an unknown id is a no-op (commit ad7a9b9, test 81de924). The existing store test pinned the throw; it now checks that the second removal does not throw. Dropped: `TitleTrophies.cpp` `file_size` may throw `filesystem_error`. `filesystem_error` derives from `std::system_error`, which derives from `std::runtime_error`, and `loadTitleFile` catches `std::runtime_error`, so the exception does not escape. Commits: - e65aec5 fix(libSceNpTrophy2): return false for a negative trophy id instead of throwing - 95ac706 test(libSceNpTrophy2): cover a negative trophy id in NpTrophy2RecordUnlock - ad7a9b9 fix(libSceNpTrophy2): ignore an unknown listener id in RemoveUnlockListener - 81de924 test(libSceNpTrophy2): expect no throw when a listener is removed twice ### Tested Linux archive build on this host (kernel 6.1), run through the shared build lock with `run_tests.sh '^np_trophy2_store$' np_trophy2_store_tests`: `BUILD-EXIT 0`, `1/1 Test #2459: np_trophy2_store ... Passed`, 100% passed. `python3 tools/check_conventions.py --base upstream/main` clean; `git diff --check upstream/main` clean. Not run against the unfixed code (no negative control was executed). Not run: `guest_nptrophy2`, Windows, macOS, a title. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
mashingaan commented 2026-11-02 11:36:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mashingaan on 2026-11-02T11:36:26Z.

Review: APPROVED


Reviewed head 81de9243d2. Both changed C ABI paths now avoid exceptions for invalid trophy IDs and repeated listener removal, and the added cases cover both regressions. Hosted Windows and required workflow checks pass on this exact head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5735942519 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15019#pullrequestreview-5735942519). Originally posted by [mashingaan](https://github.com/mashingaan) on 2026-11-02T11:36:26Z. **Review:** APPROVED --- Reviewed head 81de9243d25f5cc1576f8bde50803e4d389b5bbc. Both changed C ABI paths now avoid exceptions for invalid trophy IDs and repeated listener removal, and the added cases cover both regressions. Hosted Windows and required workflow checks pass on this exact head.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!15019
No description provided.