Skip to content

layer: remove unused error return from .Size() and .DiffSize()#43182

Merged
thaJeztah merged 3 commits intomoby:masterfrom
thaJeztah:layer_remove_unused_error
Feb 17, 2022
Merged

layer: remove unused error return from .Size() and .DiffSize()#43182
thaJeztah merged 3 commits intomoby:masterfrom
thaJeztah:layer_remove_unused_error

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

None of the implementations used return an error, so removing the error
return can simplify using these.

@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Jan 24, 2022
@thaJeztah thaJeztah requested a review from tonistiigi as a code owner January 24, 2022 14:59
@thaJeztah thaJeztah force-pushed the layer_remove_unused_error branch 2 times, most recently from f26a3c3 to f5d35b6 Compare January 24, 2022 15:48
None of the implementations used return an error, so removing the error
return can simplify using these.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
None of the implementations returned an error for this function, so removing it.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the layer_remove_unused_error branch from f5d35b6 to f9a1846 Compare January 24, 2022 17:45
@thaJeztah
Copy link
Copy Markdown
Member Author

@tonistiigi this LGTY?

Copy link
Copy Markdown
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

Isn't it better that Size() has the same signature as RWLayer?

@thaJeztah
Copy link
Copy Markdown
Member Author

So, that crossed my mind, but "it's complicated"

The current situation is:

  • Layer and RWLayer are distinct interfaces
  • They do share some properties:
    • both have a TarStreamer interface (embedded)
    • both have Parent()
    • both have Size()
    • both have Metadata()
  • So one possible option would be to extract the common properties to a common interface
  • However... Layer.Size() and RWLayer.Size() are not equivalents; Layer.Size() is the size of the whole layer chain (Layer + Parents), but RWLayer.Size() is only the size of the RWLayer itself
  • So the closest "equivalent" of RWLayer.Size() would be Layer.DiffSize()

Based on the above, at least in the current state of things, I think there's enough differences between the two to change the signature independently

Alternative

So, an alternative could be to;

  • Add a Layer.ChainSize() function, which would be the equivalent to the current Layer.Size()
  • Change Layer.Size() to do what Layer.DiffSize() does currently (return the (RW)Layer's own size); this function would never return an error in both cases.
  • Move Size() and Parent() into a common interface
  • TBD: move Metadata() into that interface (but TBD: Metadata() originates from storage-drivers, so perhaps it shoud be an interface there that we can embed)

@thaJeztah
Copy link
Copy Markdown
Member Author

this function would never return an error in both cases.

Arf, so that's not correct; RWLayer.Size() can return an error, but Layer.Size() won't

@tianon
Copy link
Copy Markdown
Member

tianon commented Feb 16, 2022

Do we gain anything from having an explicitly shared interface?

Copy link
Copy Markdown
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

LGTM -- IMO we're better off not returning an error object if it's always nil (it's just confusing to consumers to have an error return that's always nil), especially if we don't see any cases where it might not be in the future.

(Assuming there's not an actual benefit to making these share a common interface -- it seems more for cognitive load of using each of them than technical benefits?)

(Edit: see also https://twitter.com/cpuguy83/status/1492024002704863233 for a real world case where this type of misleading return signature causes pain 🙈)

@thaJeztah thaJeztah merged commit 32e5fe5 into moby:master Feb 17, 2022
@thaJeztah thaJeztah deleted the layer_remove_unused_error branch February 17, 2022 19:51
@thaJeztah thaJeztah added this to the 21.xx milestone Feb 18, 2022
@thaJeztah thaJeztah added the area/images Image Service label Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/images Image Service kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants