Skip to content

Instantly share code, notes, and snippets.

@tony612
Last active March 10, 2017 06:36
Show Gist options
  • Select an option

  • Save tony612/bc3ca0eac9054094237b789eea71251a to your computer and use it in GitHub Desktop.

Select an option

Save tony612/bc3ca0eac9054094237b789eea71251a to your computer and use it in GitHub Desktop.
Generate Dash cheatset for gRPC(status code)
# https://github.com/Kapeli/cheatset#readme
# https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
body = <<-DOC
| Client Application cancelled the request | CANCELLED | Both |
| Deadline expires before server returns status | DEADLINE_EXCEEDED | Both |
| Method not found at server | UNIMPLEMENTED | Server|
| Server shutting down | UNAVAILABLE | Server|
| Server side application throws an exception (or does something other than returning a Status code to terminate an RPC) | UNKNOWN | Server|
| No response received before Deadline expires. This may occur either when the client is unable to send the request to the server or when the server fails to respond in time. | DEADLINE_EXCEEDED | Both|
| Some data transmitted (e.g., request metadata written to TCP connection) before connection breaks | UNAVAILABLE | Client |
| Could not decompress, but compression algorithm supported (Client -> Server) | INTERNAL | Server |
| Could not decompress, but compression algorithm supported (Server -> Client) | INTERNAL | Client |
| Compression mechanism used by client not supported at server | UNIMPLEMENTED | Server |
| Server temporarily out of resources (e.g., Flow-control resource limits reached) | RESOURCE_EXHAUSTED | Server|
| Client does not have enough memory to hold the server response | RESOURCE_EXHAUSTED | Client |
| Flow-control protocol violation | INTERNAL | Both |
| Error parsing returned status | UNKNOWN | Client |
| Incorrect Auth metadata ( Credentials failed to get metadata, Incompatible credentials set on channel and call, Invalid host set in `:authority` metadata, etc.) | UNAUTHENTICATED | Both |
| Request cardinality violation (method requires exactly one request but client sent some other number of requests) | UNIMPLEMENTED | Server|
| Response cardinality violation (method requires exactly one response but server sent some other number of responses) | UNIMPLEMENTED | Client|
| Error parsing response proto | INTERNAL | Client|
| Error parsing request proto | INTERNAL | Server|
DOC
# http://www.grpc.io/grpc/cpp/impl_2codegen_2status__code__enum_8h_source.html
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,
'DO_NOT_USE' => -1
}
entries = body.split("\n").map do |line|
note, name, cs = line.split(/\s*\|\s*/).select { |part| part && part.length > 0 }
{note: note, name: name, cs: cs, code: StatusCode[name]}
end
entries << {note: 'Success', name: 'OK', code: 0, cs: 'Both'}
server_str = client_str = ""
entries.sort_by { |entry| entry[:code] }.each do |entry|
str =
"
entry do
command '#{entry[:name]}'
name '#{entry[:code]}'
notes '#{entry[:note]}'
end
"
case entry[:cs].downcase
when 'server'
server_str += str
when 'client'
client_str += str
else
server_str += str
client_str += str
end
end
output = "
cheatsheet do
title 'gRPC' # Will be displayed by Dash in the docset list
docset_file_name 'grpc' # Used for the filename of the docset
keyword 'grpc' # Used as the initial search keyword (listed in Preferences > Docsets)
# resources 'resources_dir' # An optional resources folder which can contain images or anything else
introduction \"
Status code: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
\"
category do
id 'Client generated' # Must be unique and is used as title of the category
#{client_str}
end
category do
id 'Server generated' # Must be unique and is used as title of the category
#{server_str}
end
notes \"
Go: https://github.com/grpc/grpc-go/blob/master/codes/codes.go
Java: https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/Status.java
\"
end
"
tmp_path = '/tmp/grpc_dash_cs.rb'
tmp_f = File.new(tmp_path, 'w')
tmp_f.write(output)
puts "Run `cheatset generate #{tmp_path} && open grpc.docset`"
@tony612
Copy link
Copy Markdown
Author

tony612 commented Mar 10, 2017

Preview:
dash

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