Simple refactor - extracted code for getting object size and slightly improved error types.
It's required for D14646
cargo check