Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethrowing duplication errors as CodecException #1376

Closed
Warmek opened this issue Jan 12, 2023 · 4 comments
Closed

Rethrowing duplication errors as CodecException #1376

Warmek opened this issue Jan 12, 2023 · 4 comments
Labels
core Impact core of Leshan enhancement Improvement of existing features

Comments

@Warmek
Copy link
Contributor

Warmek commented Jan 12, 2023

Question

When a SEND containing a duplicates (same path + timestamp) is received, TimestampedLwM2mNodes.Builder::build throws an IllegalArgumentException.

if (noDuplicate && previous != null) {
    throw new IllegalArgumentException(String.format(
             "Unable to create TimestampedLwM2mNodes : duplicate value for path %s. (%s, %s)",
             internalNode.path, internalNode.node, previous));
}

That exception is just catched in SendResource::handlePOST, to be sent to the SendListener::onError callback and rethrown.

} catch (RuntimeException e) {
    sendHandler.onError(registration, e);
    throw e;
}

Maybe it would be better to catch that exception (in LwM2mNodeSenMLDecoder::decodeTimestampedNodes) and rethrow as CodecException?

} catch (SenMLException | IllegalArgumentException e) {
        String hexValue = content != null ? Hex.encodeHexString(content) : "";
        throw new CodecException(e, "Unable to decode nodes : %s", hexValue, e);
}
@Warmek Warmek added the question Any question about leshan label Jan 12, 2023
@sbernard31
Copy link
Contributor

Yep totally agree ! Good catch 👍 !

@sbernard31 sbernard31 added core Impact core of Leshan enhancement Improvement of existing features and removed question Any question about leshan labels Jan 12, 2023
@Warmek
Copy link
Contributor Author

Warmek commented Jan 13, 2023

I've made a commit on opl/rethrow_illegalArgumentException

@sbernard31
Copy link
Contributor

Yep I think you can create a PR

@sbernard31
Copy link
Contributor

Fix in master by #1377.

Thx @Warmek for catching this 😉 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Impact core of Leshan enhancement Improvement of existing features
Projects
None yet
Development

No branches or pull requests

2 participants