feat(lightpush)!: return new error messages (#2115)

* feat: return new error messages

* fix test, remove unused

* up

* up

* rollback

* up test
This commit is contained in:
Sasha 2024-08-29 11:20:19 +02:00 committed by GitHub
parent eadb85ab83
commit a022433851
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 72 additions and 8 deletions

View File

@ -121,7 +121,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
return {
success: null,
failure: {
error: ProtocolError.REMOTE_PEER_FAULT,
error: ProtocolError.NO_STREAM_AVAILABLE,
peerId: peer.id
}
};
@ -170,7 +170,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
if (!res || !res.length) {
return {
failure: {
error: ProtocolError.REMOTE_PEER_FAULT,
error: ProtocolError.NO_RESPONSE,
peerId: peer.id
},
success: null
@ -211,7 +211,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
return {
success: null,
failure: {
error: ProtocolError.REMOTE_PEER_FAULT,
error: ProtocolError.NO_STREAM_AVAILABLE,
peerId: peer.id
}
};
@ -243,7 +243,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
return {
success: null,
failure: {
error: ProtocolError.REMOTE_PEER_FAULT,
error: ProtocolError.NO_RESPONSE,
peerId: peer.id
}
};

View File

@ -20,6 +20,7 @@ import { Uint8ArrayList } from "uint8arraylist";
import { BaseProtocol } from "../base_protocol.js";
import { PushRpc } from "./push_rpc.js";
import { isRLNResponseError, matchRLNErrorMessage } from "./utils.js";
const log = new Logger("light-push");
@ -153,7 +154,19 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
return {
success: null,
failure: {
error: ProtocolError.REMOTE_PEER_FAULT,
error: ProtocolError.NO_RESPONSE,
peerId: peer.id
}
};
}
if (isRLNResponseError(response.info)) {
const rlnErrorCase = matchRLNErrorMessage(response.info!);
log.error("Remote peer rejected the message: ", rlnErrorCase);
return {
success: null,
failure: {
error: rlnErrorCase,
peerId: peer.id
}
};

View File

@ -0,0 +1,31 @@
import { ProtocolError } from "@waku/interfaces";
// should match nwaku
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/rln_relay.nim#L309
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim#L20
const RLN_GENERATION_PREFIX_ERROR = "could not generate rln-v2 proof";
export const isRLNResponseError = (info?: string): boolean => {
if (!info) {
return false;
}
return info.includes(RLN_GENERATION_PREFIX_ERROR);
};
export const matchRLNErrorMessage = (info: string): ProtocolError => {
const rlnErrorMap: { [key: string]: ProtocolError } = {
[ProtocolError.RLN_IDENTITY_MISSING]: ProtocolError.RLN_IDENTITY_MISSING,
[ProtocolError.RLN_MEMBERSHIP_INDEX]: ProtocolError.RLN_MEMBERSHIP_INDEX,
[ProtocolError.RLN_LIMIT_MISSING]: ProtocolError.RLN_LIMIT_MISSING
};
const infoLowerCase = info.toLowerCase();
for (const errorKey in rlnErrorMap) {
if (infoLowerCase.includes(errorKey.toLowerCase())) {
return rlnErrorMap[errorKey];
}
}
return ProtocolError.RLN_PROOF_GENERATION;
};

View File

@ -179,7 +179,7 @@ export enum ProtocolError {
* The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
* or `DECODE_FAILED` can be used.
*/
REMOTE_PEER_FAULT = "Remote peer fault",
NO_RESPONSE = "No response received",
/**
* The remote peer rejected the message. Information provided by the remote peer
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
@ -190,7 +190,27 @@ export enum ProtocolError {
* The protocol request timed out without a response. This may be due to a connection issue.
* Mitigation can be: retrying after a given time period
*/
REQUEST_TIMEOUT = "Request timeout"
REQUEST_TIMEOUT = "Request timeout",
/**
* Missing credentials info message.
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L186
*/
RLN_IDENTITY_MISSING = "Identity credentials are not set",
/**
* Membership index missing info message.
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L188
*/
RLN_MEMBERSHIP_INDEX = "Membership index is not set",
/**
* Message limit is missing.
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
*/
RLN_LIMIT_MISSING = "User message limit is not set",
/**
* General proof generation error message.
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
*/
RLN_PROOF_GENERATION = "Proof generation failed"
}
export interface Failure {

View File

@ -101,7 +101,7 @@ class LightPushSDK extends BaseProtocolSDK implements ILightPushSDK {
failures.push(failure);
}
} else {
log.error("Failed to send message to peer", result.reason);
log.error("Failed unexpectedly while sending:", result.reason);
failures.push({ error: ProtocolError.GENERIC_FAIL });
}
}