Skip to content

fix(handshake): check node response envelope instead of blindly returning result#109

Open
Sentinel-Bluebuilder wants to merge 1 commit into
sentinel-official:developmentfrom
Sentinel-Bluebuilder:fix/handshake-response-error-checking
Open

fix(handshake): check node response envelope instead of blindly returning result#109
Sentinel-Bluebuilder wants to merge 1 commit into
sentinel-official:developmentfrom
Sentinel-Bluebuilder:fix/handshake-response-error-checking

Conversation

@Sentinel-Bluebuilder

Copy link
Copy Markdown

What

handshake() in src/utils.ts now validates the node's response envelope before returning, instead of blindly returning response.data.result.

Why

Every node response is wrapped as NodeResponse { success: boolean, result?, error?: { code, message } } (see src/types.ts). A failed handshake — bad signature, session not active on-chain, or any node-side error — can come back as HTTP 200 with success: false and an error payload. axios does not throw on that, so the old code:

// .result, supponsing success: True and error doesn't exist
return response.data.result as NodeHandshakeResult;

returned undefined (the comment even admits it assumes the happy path). The failure then surfaced much later as an opaque crash during tunnel setup (result.addrs of undefined, etc.) instead of a clear, actionable error at the handshake boundary.

Change

const payload = response.data as NodeResponse;

if (!payload.success || payload.error) {
    const code = payload.error?.code;
    const message = payload.error?.message ?? "unknown node error";
    throw new Error(`Handshake rejected by node${code !== undefined ? ` (code ${code})` : ""}: ${message}`);
}
if (!payload.result) {
    throw new Error("Handshake response missing result payload");
}
return payload.result as NodeHandshakeResult;

JSDoc @throws updated to document the new behavior. No type changes needed — NodeResponse / NodeResponseError already model this exactly.

Scope / relationship to #75

This is the clean, correctly-scoped implementation of the original error-checking request (#34). The earlier #75 was titled "add response error checking" but never touched the return path — it only flipped uuiduid in an example (a change already merged as wrong via #90 and rejected once in #78). #75 has been closed; this PR does what #34 actually asked for, against src/utils.ts, and nothing else.

Verification

tsc --noEmit passes clean on this branch.

Follow-up (not in this PR)

nodeInfo() (same file) has the identical pattern — return (response.data as NodeResponse).result as NodeInfo with no success/error check. Left out to keep this PR focused on the handshake path; happy to send a sibling PR applying the same guard there.

…ning result

The node wraps every response as { success, result?, error? }. A failed
handshake (bad signature, session not active on-chain, node-side error) can
arrive as HTTP 200 with success:false and an error payload. The previous code
returned response.data.result unconditionally (with a comment literally
'supposing success: True and error doesn't exist'), so failures surfaced as
undefined further down the tunnel-setup path instead of a clear error.

Now handshake() throws a descriptive error (including the node's error code and
message when present) on success:false / error payload, and on a successful
response missing result. JSDoc @throws updated to match.

Closes the original intent of sentinel-official#34. The mistitled sentinel-official#75 promised this but never
implemented it (and re-introduced a separately-rejected uid change); this is the
clean, correctly-scoped version against src/utils.ts.
Sentinel-Bluebuilder added a commit to Sentinel-Bluebuilder/sentinel-js-sdk-1 that referenced this pull request Jun 12, 2026
…ning result blindly

nodeInfo() returned (response.data as NodeResponse).result without checking
the { success, result?, error? } envelope. On an HTTP-200 success:false
response the function returned undefined, which then crashed downstream in
node selection / connection setup with an unrelated error.

Mirror the envelope check from the handshake() fix (sentinel-official#109): throw a descriptive
error carrying the node's code + message on success:false / error payload, and
throw when result is missing. Sibling of sentinel-official#109 - same unchecked-result bug.

Verified: tsc --noEmit exit 0.
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