Skip to content

Improve error message. #644

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

Merged
merged 2 commits into from
Jul 22, 2020

Conversation

joemphilips
Copy link
Contributor

... for ChannelError and APIMisuseError
Before this commit, When rl returns error, we don't know
The actual parameter which caused the error.
By returning parameterised String instead of predefined &'static str,
We can give a caller improved error message.

This will make my life easier when I'm debugging my server by connecting to other lightning nodes.
But I'm not sure if this is a sane approach. So I want to have a concept ACK before continuing my work.
The code does not compile but I suppose it is good enough to show what I'm trying to do to a reviewer.

@jkczyz
Copy link
Contributor

jkczyz commented Jun 22, 2020

Thanks for taking the initiative on this, @joemphilips!

I'd also like to see some improvements around our error API. I opened up issue #576 awhile back to discuss such improvements. Would love to get your input on this. Having feedback from someone actively experimenting with Rust Lightning will be valuable. And, of course, I'd welcome any contributions you'd like to make.

Regarding this PR, I agree that the message should provide more details to the user. I'd probably opt for using explicit conditions and format! over using the check_or constructs. Adding a local variable for capturing the expected should be fine.

@jkczyz jkczyz self-requested a review June 22, 2020 17:41
@joemphilips
Copy link
Contributor Author

@jkczyz
Right now for my FFI code, type information about an error is completely lost in FFI boundary, this is because passing smart enum (enum with fields) over FFI boundary are not straightforward. So instead I've just returning its message as a buffer.

So far I'm happy with this approach, so I don't have much opinion about how we compose error types. But thanks for letting me know about #576 anyway, I may have something to say in the future.

Regarding this PR, I agree that the message should provide more details to the user. I'd probably opt for using explicit conditions and format! over using the check_or constructs. Adding a local variable for capturing the expected should be fine.

Thanks, I will continue with that approach.

@joemphilips joemphilips force-pushed the improve_error_message branch from 9b67db5 to cd7c94d Compare July 2, 2020 05:47
@joemphilips
Copy link
Contributor Author

Ready for review. I don't know why Travis CI is failing. I think it has nothing to do with my change.

@joemphilips joemphilips force-pushed the improve_error_message branch 4 times, most recently from aac2c8d to f2b53e9 Compare July 3, 2020 03:30
@joemphilips joemphilips changed the title WIP: improve error message. Improve error message. Jul 3, 2020
@joemphilips joemphilips force-pushed the improve_error_message branch from 1b21715 to 11a2d7f Compare July 4, 2020 10:42
joemphilips added a commit to joemphilips/NRustLightning that referenced this pull request Jul 6, 2020
@valentinewallace valentinewallace self-requested a review July 8, 2020 20:05
Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review

I'm a fan of these changes, they would've definitely helped me a debug more quickly in the past

One thing is, I think we prefer every commit to compile and pass tests -- I'm guessing commits prior to f2b53e9c99dda14fbb6e3d820de147ee1e08a9ff wouldn't pass at the moment?

@joemphilips joemphilips force-pushed the improve_error_message branch from 11a2d7f to bc1d1a8 Compare July 9, 2020 10:51
@joemphilips
Copy link
Contributor Author

Addressed @valentinewallace 's review and squashed some commits so that every commits pass tests.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick feedback turnaround!

@valentinewallace
Copy link
Contributor

valentinewallace commented Jul 10, 2020

Great thanks, could you squash in the last two commits then I'll approve?

@joemphilips joemphilips force-pushed the improve_error_message branch from 8f89271 to 68b3a4f Compare July 11, 2020 02:46
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Thanks for going through all these error strings!

@@ -881,7 +881,7 @@ mod tests {
assert_eq!(route.paths[0][0].fee_msat, 200);
assert_eq!(route.paths[0][0].cltv_expiry_delta, (13 << 8) | 1);
assert_eq!(route.paths[0][0].node_features.le_flags(), &vec![0b11]); // it should also override our view of their features
assert_eq!(route.paths[0][0].channel_features.le_flags(), &Vec::new()); // No feature flags will meet the relevant-to-channel conversion
assert_eq!(route.paths[0][0].channel_features.le_flags(), &Vec::<u8>::new()); // No feature flags will meet the relevant-to-channel conversion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my compiler complains that it cannot infer the type. (in every rustc version.). I have absolutely no idea why this happens only in this branch, it works fine in master. But giving an type annotation does not hurt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange. I was able to reproduce this but am unsure what would cause rustc to complain.

@joemphilips joemphilips force-pushed the improve_error_message branch 2 times, most recently from 9c04b33 to e79317d Compare July 13, 2020 04:30
@joemphilips
Copy link
Contributor Author

Addressed @jkczyz 's review and re-split commits.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this detailed PR!

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didnt check every line in the diff, but seems good pending val and Jeff's review.

@@ -28,3 +28,4 @@ features = ["bitcoinconsensus"]

[dev-dependencies]
hex = "0.3"
regex = "0.1.80"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not regex 1.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the latest release version which compiles in rustc 1.22.0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. Hmm, looks like their MSRV is still 1.28 (https://github.com/rust-lang/regex/blob/master/.github/workflows/ci.yml#L34) maybe lets just finally bump the MSRV to that given rust-bitcoin may bump to 1.29 sooner or later anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose bumping the MSRV should be done with other PR so should I rebase after that PR gets merged? I think it is fine to use old regex though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@joemphilips joemphilips force-pushed the improve_error_message branch from e79317d to 6a2ae52 Compare July 14, 2020 01:52
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

In the future, it would be less daunting for reviewers if the PR could be broken into more atomic commits. For instance, here one commit to switch from &'static str to String and another to update the error messages.

@@ -881,7 +881,7 @@ mod tests {
assert_eq!(route.paths[0][0].fee_msat, 200);
assert_eq!(route.paths[0][0].cltv_expiry_delta, (13 << 8) | 1);
assert_eq!(route.paths[0][0].node_features.le_flags(), &vec![0b11]); // it should also override our view of their features
assert_eq!(route.paths[0][0].channel_features.le_flags(), &Vec::new()); // No feature flags will meet the relevant-to-channel conversion
assert_eq!(route.paths[0][0].channel_features.le_flags(), &Vec::<u8>::new()); // No feature flags will meet the relevant-to-channel conversion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange. I was able to reproduce this but am unsure what would cause rustc to complain.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -28,3 +28,4 @@ features = ["bitcoinconsensus"]

[dev-dependencies]
hex = "0.3"
regex = "0.1.80"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

... for ChannelError and APIMisuseError
Before this commit, When rl returns error, we don't know
The actual parameter which caused the error.
By returning parameterised `String` instead of predefined `&'static str`,
We can give a caller improved error message.

TestLogger now has two additional methods
1. `assert_log_contains` which checks the logged messsage
  has how many entry which includes the specified string as a substring.
2. `aasert_log_regex` mostly the same with `assert_log_contains`
  but it is more flexible that caller specifies regex which has
  to be satisfied instead of just a substring.
For regex, tests now includes `regex` as dev-dependency.
For making debugging easy.
If the user gives a different node_secret for transport
layer (`PeerManager`) and for routing msg, internal_announcement_signatures
is the first place it causes an error.
By giving a detailed error message, user will be able to
fix the bug quickly.
@joemphilips joemphilips force-pushed the improve_error_message branch from 6a2ae52 to 407e306 Compare July 22, 2020 01:35
@TheBlueMatt TheBlueMatt merged commit 50df4cf into lightningdevkit:master Jul 22, 2020
@joemphilips joemphilips deleted the improve_error_message branch August 8, 2020 02:38
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.

5 participants