question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Status Codes are shown in incorrect alphabetical ordering

See original GitHub issue

I don’t know why, but the StatusCode enums are in the wrong order.

https://github.com/grpc/grpc-web/blob/1779661dded5b918cdd84a216f708b93ebf2384c/packages/grpc-web/index.d.ts#L130

That shows them sorted alphabetically, but they are not actually that way at all. The actual ordering:

StatusCode: {
          OK: 0,
          CANCELLED: 1,
          UNKNOWN: 2,
          INVALID_ARGUMENT: 3,
          DEADLINE_EXCEEDED: 4,
          NOT_FOUND: 5,
          ALREADY_EXISTS: 6,
          PERMISSION_DENIED: 7,
          UNAUTHENTICATED: 16,
          RESOURCE_EXHAUSTED: 8,
          FAILED_PRECONDITION: 9,
          ABORTED: 10,
          OUT_OF_RANGE: 11,
          UNIMPLEMENTED: 12,
          INTERNAL: 13,
          UNAVAILABLE: 14,
          DATA_LOSS: 15
        }

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sampajanocommented, Sep 21, 2022

Oh wow thanks for the very detailed explanation! It’s very interesting to know! 😃

I’m not familiar with NextJS so maybe it’s somehow directly compile the TS enum into numbers (unlike the TS example we have, which pretty much generated the same JS code and was working fine for us.)

We’ll definitely keep this difference in mind going forward, and will be careful about future enums!

Thanks a lot for your report and code fix! 😃

0reactions
chandraadityacommented, Sep 20, 2022

Not a problem!

So I’m using NextJS and I’m not entirely sure how it compiles TS and if it does some weird stuff.

But essentially what was happening was I needed to check if the response was NOT_FOUND so I did rpcError.code == grpcWeb.StatusCode.NOT_FOUND, and that was for sure causing errors during runtime.

Because even though my server is sending the NOT_FOUND response which is error code 5, rpcError.Code was actually interpreted as FAILED_PRECONDITION which is error code 5. So during the check in the IF statement, rpcError.code is 5 on the left side, then on the right side grpcWeb.StatusCode.NOT_FOUND is actually 8 so that condition was failing and my code was never executed even though it is expected to pass.

But apart from the fact that my code was not working, I’m not 100% sure what the reason was, I do remember trying to console.log the if condition and it showing 5 and 8 which is when I switched from grpcWeb.StatusCode.NOT_FOUND to just 5 like so: rpcError.code.valueOf() === 5 And it started working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alphabetical error summary - Dialogic
Error name Hex Decimal NFXERR_BAD_FILE_FORMAT 0x050207 328199 NFXERR_BAD_PAGE_SIZE 0x05020B 328203 NFXERR_BUFFER_UNDERRUN 0x050211 328209
Read more >
Why Word's Alphabetical order is different from a dictionary
For alphabetical sorting upper and lower case letters are treated the same, despite having different ASCII values. The usual answer is wrong.
Read more >
Python Alphabetical order by sort method shows wrong order
I am just learning python and I came across a code for sorting words alphabetically. My code is: my_str="Welcome to Python" words =...
Read more >
ICD-10-CM Official Guidelines for Coding and Reporting - CMS
A code listed next to a main term in the ICD-10-CM Alphabetic Index is referred to as a default code. The default code...
Read more >
Understanding MARC Bibliographic: Parts 7 to 10
The most common subfield codes used with each tag are shown. Each subfield code is ... Subfields $v, $x, $y, and $z do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found