Skip to content

[system] Add centralized status and POC for hello#240

Draft
esnguyen wants to merge 1 commit intogoogle:mainfrom
esnguyen:esnguyen/status_phase1
Draft

[system] Add centralized status and POC for hello#240
esnguyen wants to merge 1 commit intogoogle:mainfrom
esnguyen:esnguyen/status_phase1

Conversation

@esnguyen
Copy link
Collaborator

We want to centralize the error status by goign with a compacted 64 bit error reporting format. This can provide context, domain, and specific error code. The hello would is used to create an example of the error code foundation. This doesnt include the utlility to convert 64 error to human readable yet

We want to centralize the error status by goign with a compacted 64 bit
error reporting format. This can provide context, domain, and specific
error code. The hello would is used to create an example of the error
code foundation. This doesnt include the utlility to convert 64 error to
human readable yet

Signed-off-by: Ellis Nguyen <sarzanguyen@google.com>
typedef uint64_t libhoth_error;

#define LIBHOTH_ERR_CONSTRUCT(ctx, space, code) \
(((uint64_t)(ctx) << 32) | ((uint64_t)(space) << 16) | (uint64_t)(code))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Would it be a good idea to mask (at least) space and code? or maybe add a static_assert to ensure that they are not more than 16 bits in size?

Otherwise misuse of this macro can cause confusion (since the macro does not mention what type to use for each parameter). Eg:

#include <stdint.h>
#include <stdio.h>

#define LIBHOTH_ERR_CONSTRUCT(ctx, space, code) \
  (((uint64_t)(ctx) << 32) | ((uint64_t)(space) << 16) | (uint64_t)(code))

int main(void) {
    printf("0x%lx\n", LIBHOTH_ERR_CONSTRUCT(0x66778899, 0xAABBCC, 0xDDEEFF));
}

Output: 0x667788bbbbddeeff

Copy link
Collaborator

Choose a reason for hiding this comment

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

making this an inline function is also an option. That way the type of parameters is more clear, and the compiler can handle truncation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants