Skip to content

feat(npwebapi): implement error code parsing - #23222

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Thimo188:feat/npwebapi-get-error-code
Nov 24, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Thimo188:feat/npwebapi-get-error-code

Conversation

@Thimo188

@Thimo188 Thimo188 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

Implement sceNpWebApiGetErrorCode with the firmware 13.42 signature and forwarding behavior. SDKs before 2.50 use the single-error libSceNpCommon parser, newer SDKs use its multi-error parser, and the two observed parser errors are translated to their libSceNpWebApi results. Use the current ApplicationCompiledSdkVersion() helper after the old helper was removed, and record the remaining parser-mapping limitation with exact module and error-code evidence.

Tested

Ubuntu 24.04 linux/amd64 Docker (anyps5-dev:24.04) after rebase onto current main: built guest_np_web_api_tests, guest_np_web_api_initialize_tests, and guest_np_web_api2_tests; ctest --test-dir build-codex -R "^guest_np_web_api" --output-on-failure passed 3/3. git diff --check, python3 tools/debt_fold.py --check, and python3 tools/check_conventions.py --base origin/main passed. The branch overlap check found only this existing PR.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

@PrivacyOnion PrivacyOnion 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.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 6bc9fef574:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_np_web_api_tests built cleanly.
  • CTest (guest_np_web_api):
    1/1 Test #4847: guest_np_web_api .................   Passed    0.09 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNpWebApi/Export.cpp, core/libs/prx/libSceNpWebApi/include/Api.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified sceNpWebApiGetErrorCode signature APS5_VABI (std::int32_t httpStatus, const char* json, std::size_t length) in core/libs/prx/libSceNpWebApi/include/Api.hpp and Export.cpp.
    • Verified SDK version dispatch logic using compiledSdkVersion() >= SDK_VERSION_2_50 forwarding to sceNpServerErrorJsonMultiGetErrorCode vs sceNpServerErrorJsonGetErrorCode.
    • Verified error code translations for SCE_NP_SERVER_ERROR_JSON_BAD_CODE (0x80559C02 -> 0x8055A401) and SCE_NP_SERVER_ERROR_JSON_BAD_FORMAT (0x80559C03 -> 0x80552914) match PS5 firmware conventions.
    • Verified CMake target_link_libraries(libSceNpWebApi PRIVATE libSceNpCommon) correctly links libSceNpCommon for the forwarded parser symbols.
    • Verified debt fragment docs/dev/debt/changes/feat-npwebapi-get-error-code.md complies with debt format rules and accurately records the SDK version dispatch gap.
    • Verified tests in core/libs/tests/GuestNpWebApi.cpp thoroughly exercise both SDK < 2.50 and >= 2.50 code paths, fallback behavior on null body, and restore SDK version state.

Looks Good To Me

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Progress report (5e9ad5f → 76565d3)

📈 System libraries: 46.58% (+0.0025%, +1 implemented function)

✅ 1 implemented
Library Name
libSceNpWebApi sceNpWebApiGetErrorCode

Changed libraries (implemented exports)

Library Before After Change
libSceNpWebApi 55/94 (58.51%) 56/94 (59.57%) +1.06%

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows result for head 6bc9fef574, merged alone into main 67d3465feb (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. This PR adds no other build failure.

guest_np_web_api, the test this PR adds or extends, passes 3 of 3 runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@MarcZX10 MarcZX10 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.

Reviewed — looks good

The implementation matches the stated SDK-dependent forwarding behavior, and the inspected tests cover both parser modes and HTTP fallback.

What I ran

Reviewed head 6bc9fef57445df6c24b13e7570cf9187bd77e140. No commands or tests were run by me; the author reports a passing test and checks in the PR description.

Results

Check Result Note
Source review passed Implementation and relevant parser code inspected
Tests run by reviewer not run Author-reported results are not reviewer runs

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read all five changed files listed as reviewed in the manifest: core/libs/prx/libSceNpWebApi/CMakeLists.txt, core/libs/prx/libSceNpWebApi/Export.cpp, core/libs/prx/libSceNpWebApi/include/Api.hpp, core/libs/tests/GuestNpWebApi.cpp, and docs/dev/debt/changes/feat-npwebapi-get-error-code.md. The review bundle had no excluded files. I also read relevant sections of core/libs/prx/libSceNpCommon/Json.cpp and core/libs/tests/GuestNpCommonRuntime.cpp. Build/test outputs and physical console behavior were not independently verified.

To get this to a good state

Nothing is required.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 6bc9fef574, applied with git apply (with -C1, context shifted) on main fd4aeed483 together with the other 26 PRs of one batch (#24498, #24665, #17297, #21499, #21726, #22534, #12900, #17843, #22051, #22075, #23087, #23206, #23227, #13147, #17482, #21935, #17477, #18272, #22858, #22929, #23028, #23295, #23916, #24179, #24706, #12619). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_np_web_api, guest_np_web_api_initialize (2 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6525 tests) on the RTX 3080 has 8 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #18272 (guest_audio_out), #12900 (guest_user_service_initial_user_bounds); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_content_search. The 2125 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@Helldiverr

Copy link
Copy Markdown
Contributor

Works on Windows with a one-line rename, and one finding blocks: the PR does not build on current main. The two other points under Code are not blocking.

Existing runs:

  • maskym, Windows 11, WinLibs GCC 15.2.0: guest_np_web_api 3 of 3 at 6bc9fef574, an earlier head.
  • kiwe147, Windows 11, WinLibs GCC 15.2.0: guest_np_web_api and guest_np_web_api_initialize pass at 6bc9fef574, applied with 26 other PRs in one tree.
  • Thimo188, the Tested section: Linux (Docker, Ubuntu 24.04), guest_np_web_api 1 of 1.

No Windows output has been posted for this head before this one.

What this run adds. Windows results at fbb8773c65: the build of the merge onto current main, then main once and the merge with the rename three times, with a negative control, six mutations and a probe of inputs the tests do not cover.

Blocking: the merge does not build.

  • main f688851eba ("refactor(libc): read the title's compiled SDK version through one helper", after this head) removed the file-local compiledSdkVersion() that this head still has at Export.cpp:115-120. The other callers in libSceNpWebApi/Export.cpp now call ApplicationCompiledSdkVersion() (prx/libc/include/ApplicationHeap.hpp:31 on main 255b3fae6e), for example Export.cpp:132 on main.
  • The new call at Export.cpp:542 at the head still uses the old name. Git merges the PR onto main without a conflict, and the build of that merge (181a30a7c8) stops at this error, line 535 of the merged file:
    Export.cpp:535:24: error: 'compiledSdkVersion' was not declared in this scope; did you mean 'sceNpGetSdkVersion'?
  • Both tests are then Not Run, on all three runs.
  • The fix is the rename at Export.cpp:542: ApplicationCompiledSdkVersion() >= SDK_VERSION_2_50. The helper reads the same field, process parameters + 0x10 (ApplicationHeap.hpp:34 on main; Export.cpp:118 at the head reads + 16).
  • Every result below comes from the merge with that one line changed (8f4ace62dc, on top of 181a30a7c8).

Code.

  • Export.cpp:541-548 picks sceNpServerErrorJsonMultiGetErrorCode from SDK 2.50 and sceNpServerErrorJsonGetErrorCode below it, as the debt entry describes. TestErrorCode (GuestNpWebApi.cpp:872-888) pins both sides of the boundary, at 0x024fffff and 0x02500000. always-multi, always-single and boundary-gt in the table below each fail it.
  • Not blocking: the two mappings at Export.cpp:545-546 cannot be reached with the parser on main.
    • In libSceNpCommon/Json.cpp on main, the code callback returns NP_SERVER_ERROR_JSON_BAD_CODE for a code that is not a number or is out of range (Json.cpp:828 and :830).
    • ServerErrorCode (Json.cpp:859-870) turns every failed parse into HttpStatusError(httpStatus) (Json.cpp:866). So 0x80559C02 never leaves sceNpServerErrorJson*GetErrorCode, and nothing in libSceNpCommon returns 0x80559C03.
    • The probe confirms this at both SDK versions. A string code, a negative code, the code 99999999999, a truncated body, a body that is not JSON and a zero length each return 0x82F00194 with status 404. Status 99 returns 0x82FFFFFF. None returns 0x80559C02.
    • So no-mapping, swap-mapping and mapping-to-zero pass every test. If the firmware parser does return those two codes, the gap is in libSceNpCommon. Either way, a line in the debt entry saying that the mapping is not reached with the current parser would record it.
  • Not blocking: docs/dev/REVERSE_ENGINEERING.md:148-154 on main asks for "Where it came from: the title ID and the call-site addresses (PPSA03393, 0x76D132), or the module and firmware version" and "What each site showed".
    • The fragment (feat-npwebapi-get-error-code.md:7) names firmware 13.42 but not the module.
    • It also does not say what the disassembly showed for the SDK check or for the two codes it maps.
  • check_conventions.py --base main passes on 181a30a7c8. On 8f4ace62dc it reports only the subject of my local rename commit. debt_fold.py --check passes on both.

Negative control and mutations. The first row is the negative control. Each row is applied alone on 8f4ace62dc, and both tests are rebuilt and run once. Every build succeeded. The messages are from Require in TestErrorCode.

Mutation Change guest_np_web_api guest_np_web_api_initialize
neg-throws NotImplemented_nid_no_patch(__func__) at the top of sceNpWebApiGetErrorCode fails (exit 0xc0000409, sceNpWebApiGetErrorCode not implemented) passes
always-multi always call sceNpServerErrorJsonMultiGetErrorCode fails (exit 0xc0000409, the old error parser needs error.code) passes
always-single always call sceNpServerErrorJsonGetErrorCode fails (exit 0xc0000409, the new error parser reads a top-level code) passes
boundary-gt > instead of >= at Export.cpp:542 fails (exit 0xc0000409, the new error parser reads a top-level code) passes
no-mapping delete Export.cpp:545-546 passes passes
swap-mapping swap the two codes at Export.cpp:545-546 passes passes
mapping-to-zero both parser errors return 0 passes passes

Tests. The test set is guest_np_web_api and guest_np_web_api_initialize.

Run Commit Result
main 255b3fae6e 2 of 2 passed
merge as is, runs 1 to 3 181a30a7c8 build fails; 0 of 2, both Not Run, each run
merge with the rename, run 1 8f4ace62dc 2 of 2 passed
merge with the rename, run 2 8f4ace62dc 2 of 2 passed
merge with the rename, run 3 8f4ace62dc 2 of 2 passed
merge with the rename, the Tested section's ^guest_np_web_api$ 8f4ace62dc 1 of 1 passed

The build of 8f4ace62dc logged one -Wc++23-extensions warning from libSceAgcDriver/Execution/src/VulkanDevice.cpp:2649, which this PR does not change.

Host:

  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release
  • Commits: head fbb8773c65, merged onto main 255b3fae6e as 181a30a7c8, then the rename as 8f4ace62dc

AI-assisted: yes

@Thimo188
Thimo188 force-pushed the feat/npwebapi-get-error-code branch from fbb8773 to 76565d3 Compare November 24, 2026 14:02
@Thimo188

Copy link
Copy Markdown
Contributor Author

@Helldiverr Addressed the blocking current-main build issue in 76565d3550 by using ApplicationCompiledSdkVersion(). The debt fragment now names firmware 13.42 libSceNpWebApi.sprx, records the two mapped parser codes, and notes that the current libSceNpCommon parser makes those mappings unreachable. After rebasing onto current main, guest_np_web_api, guest_np_web_api_initialize, and guest_np_web_api2 pass 3/3; diff, debt, conventions, and overlap checks pass.

@Helldiverr

Copy link
Copy Markdown
Contributor

Works on Windows. The new head 76565d3550 merges onto current main and builds. On the merge, guest_np_web_api, guest_np_web_api_initialize and guest_np_web_api2 pass 3 of 3. The three points from the first Windows run are addressed: the build fix is in the code, and the two documentation points are in the debt fragment. The three mapping mutations still pass every test, as the fragment now records.

Existing runs:

  • Thimo188, in their reply: guest_np_web_api, guest_np_web_api_initialize and guest_np_web_api2 pass 3 of 3 after rebasing onto current main, with the diff, debt, conventions and overlap checks.
  • The first Windows run (comment 7121399546) was at fbb8773c65. That merge did not build on main 255b3fae6e.

What this run adds. This run merges 76565d3550 onto current main 7f99fbd60d and builds it without a local change. It runs main once and the merge 3 times. It re-applies the negative control and the three mutations that passed before, and re-runs the probe of inputs the tests do not cover.

Code. Line numbers are in core/libs/prx/libSceNpWebApi/Export.cpp at the head unless a file is named.

  1. The build error is fixed. :535 calls ApplicationCompiledSdkVersion(), and the head no longer has a file-local compiledSdkVersion(). The merge 571d1492b0 builds, and every row below comes from it as is.
  2. The mappings at :538-539 still cannot be reached with the parser on main, and the fragment now says so.
    • The fragment (docs/dev/debt/changes/feat-npwebapi-get-error-code.md:7) says the current libSceNpCommon parser turns parse failures into HTTP status errors before either mapped code reaches this export.
    • The probe confirms this at SDK 0x024fffff and 0x02500000. A string code, a negative code, the code 99999999999, a truncated body, a body that is not JSON and a zero length each return 0x82F00194 with status 404. Status 99 returns 0x82FFFFFF. None returns 0x80559C02 or 0x80559C03, so the result is unchanged from the first run.
    • So no-mapping, swap-mapping and mapping-to-zero still pass every test. That matches what the fragment records. A test can only pin them once the parser returns those codes.
  3. The source of the reverse engineering is now recorded. The same fragment line names firmware 13.42 libSceNpWebApi.sprx, the two codes it maps (0x80559c02, 0x80559c03) and the SDK 2.50 selection. It also says that nothing was measured on a console. That covers the module, firmware version, findings and unverified parts that docs/dev/REVERSE_ENGINEERING.md:150-154 on main asks for.
  4. Since the first run, the head's diff against main changed only in :535 and the fragment. TestErrorCode (core/libs/tests/GuestNpWebApi.cpp:872-888) is the same, and so is core/libs/prx/libSceNpWebApi/CMakeLists.txt:3, which links libSceNpCommon. The fix adds no new code path, so this run adds no new mutation.
  5. check_conventions.py against main 7f99fbd60d and debt_fold.py --check pass on the merge.

Negative control, mutations and probes. The first row is the negative control, and the last row is the probe. Each row is applied alone on the merge. The three test executables are deleted and rebuilt, and the three tests are run once. Every build succeeded. In every row, guest_np_web_api_initialize and guest_np_web_api2 pass.

Mutation Change Result
neg-throws NotImplemented_nid_no_patch(__func__) at the top of sceNpWebApiGetErrorCode (:534) guest_np_web_api fails (exit 0xc0000409, sceNpWebApiGetErrorCode not implemented)
no-mapping delete :538-539 passes, as in the first run
swap-mapping swap the two returned codes at :538-539 passes, as in the first run
mapping-to-zero both parser errors return 0 passes, as in the first run
probe no source change; the 14 probe calls run at the end of TestErrorCode passes; every call returns an HTTP status error, as listed in point 2

Tests.

Test main merge run 1 merge run 2 merge run 3
guest_np_web_api passed, 0.14 passed, 0.15 passed, 0.25 passed, 0.14
guest_np_web_api_initialize passed, 0.21 passed, 0.07 passed, 0.08 passed, 0.05
guest_np_web_api2 passed, 0.10 passed, 0.04 passed, 0.01 passed, 0.02

Times are in seconds. The main column runs the tests as they are on main.

Host:

  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release
  • Commits: head 76565d3550, merged onto main 7f99fbd60d as 571d1492b0

AI-assisted: yes

@oneandonlydean
oneandonlydean merged commit f7e5b03 into boykopovar:main Nov 24, 2026
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants