Page MenuHomePhabricator

[services] Tunnelbroker - Empty field checks in database items
ClosedPublic

Authored by max on Mar 28 2022, 6:19 AM.
Tags
None
Referenced Files
F3356346: D3525.diff
Sat, Nov 23, 6:30 PM
Unknown Object (File)
Sun, Nov 10, 5:42 AM
Unknown Object (File)
Tue, Nov 5, 11:24 AM
Unknown Object (File)
Tue, Nov 5, 11:24 AM
Unknown Object (File)
Oct 23 2024, 12:14 PM
Unknown Object (File)
Oct 23 2024, 12:13 PM
Unknown Object (File)
Oct 23 2024, 11:49 AM
Unknown Object (File)
Oct 23 2024, 7:16 AM

Details

Summary

Check multiple fields to not be empty in the database item entity.

Implemented a small checkEmptyField function in Tools which checks for an empty string and zero numbers.
Usage implementation in database items also was added.

Linear task: ENG-618

Test Plan

Successfully built and run service using yarn run-tunnelbroker-service.

Diff Detail

Repository
rCOMM Comm
Branch
check-empty-in-array
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

max retitled this revision from [services] Tunnelbroker - Empty fields checks in database items to [services] Tunnelbroker - Empty field checks in database items.Mar 28 2022, 6:24 AM
max edited the summary of this revision. (Show Details)
max added reviewers: tomek, karol, varun.
max edited the summary of this revision. (Show Details)
tomek requested changes to this revision.Mar 29 2022, 5:42 AM
tomek added inline comments.
services/tunnelbroker/src/Database/DeviceSessionItem.cpp
44–52 ↗(On Diff #10733)

I'm not sure about this approach. You still need to specify all the fields that are checked, but we lose all the info about which field was empty. If we don't want to have a lot of ifs here, maybe we can introduce a new function that takes a string to check and a message and has an if inside? Or we can simply specify all the ifs here.

services/tunnelbroker/src/Tools/Tools.cpp
70–71 ↗(On Diff #10733)

We don't want to copy them

This revision now requires changes to proceed.Mar 29 2022, 5:42 AM

Switching to checkEmptyField function which just checks the string is empty or number is zero and throw an error.

max edited the summary of this revision. (Show Details)
max added inline comments.
services/tunnelbroker/src/Database/DeviceSessionItem.cpp
44–52 ↗(On Diff #10733)

I'm not sure about this approach. You still need to specify all the fields that are checked, but we lose all the info about which field was empty. If we don't want to have a lot of ifs here, maybe we can introduce a new function that takes a string to check and a message and has an if inside? Or we can simply specify all the ifs here.

That makes sense to me. I've changed the function to simple if check with the throwing a descriptive error. In this case, we simply go with the DRY principle too and get rid of these ifs.

services/tunnelbroker/src/Tools/Tools.cpp
70–71 ↗(On Diff #10733)

We don't want to copy them

It was removed.

max marked 2 inline comments as done.
max added inline comments.
services/tunnelbroker/src/Database/DeviceSessionItem.cpp
43 ↗(On Diff #10876)

Note: SessionID and DeviceID validations were added at the child D3526 diff.

tomek requested changes to this revision.Mar 31 2022, 8:39 AM

It's a lot better now, but I'm not sure about function names

services/tunnelbroker/src/Tools/Tools.cpp
70 ↗(On Diff #10876)

Not sure about this name. For me it suggests that we want the field to be empty, but the intention was opposite. Maybe checkIfNotEmpty?

77–82 ↗(On Diff #10876)

This function doesn't check if the value is empty - it check if it is zero.

This revision now requires changes to proceed.Mar 31 2022, 8:39 AM

Rebased, changed function names by comments.

max added inline comments.
services/tunnelbroker/src/Tools/Tools.cpp
70 ↗(On Diff #10876)

Not sure about this name. For me it suggests that we want the field to be empty, but the intention was opposite. Maybe checkIfNotEmpty?

I don't mind about the name changing. I've changed it.

77–82 ↗(On Diff #10876)

This function doesn't check if the value is empty - it check if it is zero.

Ok, let's go with the specific names instead of the universal and overloaded function. I've changed it.

tomek added inline comments.
services/tunnelbroker/src/Tools/Tools.cpp
77–82 ↗(On Diff #10876)

Generally, we should prefer more universal names, but in this case isEmpty means something completely different than isZero. We need to be explicit what we're checking to avoid confusion.

This revision is now accepted and ready to land.Apr 6 2022, 6:37 AM
max marked 2 inline comments as done.

Rebase on master.

This revision was landed with ongoing or failed builds.Apr 7 2022, 2:17 AM
This revision was automatically updated to reflect the committed changes.