Is a corrupted file an Invalid Argument? - grpc

I'm programming a service with a team. The service receives a file as a byte array and returns a response. We are expecting a specific type of file (PDF, WORD, EXCEL, TXT, etc)
We are discussing what type of exception throws if the file is corrupted or invalid (a 0 bytes PDF file for example).
We are using gRPC as the communication protocol, so I'm thinking in return an Invalid Argument status code, but some coworker disagrees with me and proposes to use the Unknown status code.
Which scenarios allow me to use the Invalid Argument status code?

UNKNOWN should be reserved for cases when you don't know what sort of failure happened; this normally happens when converting errors from one type to another and it isn't clear what the original error implied.
INVALID_ARGUMENT's documentation:
// The client specified an invalid argument. Note that this differs
// from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments
// that are problematic regardless of the state of the system
// (e.g., a malformed file name).
That's exactly the case presented here, where the server does not consider the input valid.

Related

Google cloud vision API error reading pdf

I am currently trying to process a large pdf document using google cloud vision API. When reading the document I am receiving an error that says "json_format.Parse( error". I have attached my code below. How can I fix this?
Code
You are getting the error on that line of code because you are trying to pass json_string with type: <class 'bytes'> and a non existent object vision.types.AnnotateFilesResponse() to json_format.Parse() that requires:
google.protobuf.json_format.Parse(text, message,ignore_unknown_fields=False, descriptor_pool=None) Parses a JSON
representation of a protocol message into a message.
Parameters:
text – Message JSON representation.
message – A protocol buffer message to merge into.
ignore_unknown_fields – If True, do not raise errors for unknown fields.
descriptor_pool – A Descriptor Pool for resolving types. If None use
the default.
Returns The same message passed as argument.
Raises:: ParseError: On JSON parsing problems.
Since your goal is to read the response from your async_batch_annotate_files(), the JSON response from this method will be saved to the defined Cloud Storage Bucket output location. You can just read and parse the data in json_string by converting it to a dictionary. You can then work you way in the dictionary by referring to AnnotateFileResponse reference. using the code below:
output = blob_list[0]
json_string = output.download_as_string()
response = json.loads(json_string)
first_page_response = response['responses'][0]
annotation = first_page_response['fullTextAnnotation']
print('Full text:\n')
print(annotation['text'])
NOTE: Just make sure that you are getting the correct JSON response file (output = blob_list[0]), else the parsing of results will yield and error.

Posting binary buffer payload using Node-RED

I am trying to send a byte array through POST using Node-RED. I can successfully create the buffer using this module and storing it in msg.payload. However I can't figure out how to add it as a parameter in a http request node.
The receiving application requires enclosing quotes. So I use the payload in the following url: localhost:port/path?var=\"{{payload}}\", but it gives
"Error converting http params to args: invalid character '\' looking for beginning of value"
If using it in the request url without quotes: localhost:port/path?var={{payload}} nothing gets through (I can see on the other end).
I am using Protobuf due to the application on the other side, but I've also tried creating a buffer, as described here. However, nothing changes.
POSTs should not have arguments in the URL. The data should all be in the body.
Do you need to make the msg.payload an object with keys matching the arg names.
msg.payload = {
var = [buffer]
}
You will probably have to play around with the content-type header as by default I believe Node-RED will send a JSON body and you probably want application/x-www-form-urlencoded
You can set the headers by adding a msg.headers object

How to avoid parameter reference/substitution in tags and UDT

I would like to put a short JSON string in a memory tag but am getting an error: "Error expanding potential parameter reference in tag" due to the { in the JSON initiating parameter substitution. I've tried a few simple escapes such as \{, \\{ and {{, no joy.
How can I turn this off within the tag?
In Ignition 7.9.2, despite the word "error", this is merely a warning that the JSON can't be interpreted as a substitution. This warning can be ignored unless you are attempting parameter substitution.
I spoke with Ignition support, they said there is no way to avoid this warning, but that they may make improvements here to enable substitution in JSON in a future release.

What HTTP response should I use if my Request/Ack/Poll fails

I have a scenario similar to request/ack/poll. So the client posts data and I send status Accepted back. Then a background process takes care of creating the resource.
The client can then go to the location of the "Accepted response" and Poll for status.
If the background process fails and I want to inform the client about this, what status code should I return? HTTP 500 is not that good since it could also happen if the call to the status route fails for any other reason, and the client couldn't tell the difference.
And also, what is the best code to return when the creation of the resource is still in progress? 200 OK?
Any suggestions?
I defined a media type to address this issue. Here is a copy of the readme..
A status document might look like:
<status state="busy" progress="2/75" message="This is a message"/>
It consists of a root node named status and has the properties: state, progress and message.
Only the state property is required, and should be one of the following values : {waiting, busy, warning, error, ok, cancelled}
The progress property is a fraction that can be optionally used to indicate to a user how much longer we expect the resource to remain in a particular state.
The message property is a human readable string intended to qualify the resource state.
Additional information can be provided by embedding links within the status node.
<status state="ok" message="Finshed generating report">
<link rel="related" href="http://example.org/report/99/output"/>
</status>
the JSON equivalent of this would be
{ "status" : {
"state" : "ok",
"message" : "Finished generating report",
"links" : {
"related" : { "href" : "http://example.org/report/99/output"}
}
}
}
The syntax of the links object in the JSON format follows the convention of HAL except that there is no leading underscore for the links object. The underscore is unncessary as this media type does encourage embedding arbitrary additional content, therefore no naming conflicts should occur.
The specification does not prohibit extensions to the content, however it defines no rules for extensions beyond the constraints of the underlying JSON/XML format.
Media Type Identifiers
The intent is to submit this specifcation as a proposal to IANA for registration using the following identifiers:
application/status+xml
application/status+json

snmp v1 Communication Models if i have many errors in the Getrequest message how to represent it using error index?

in Network managment systems
using *SNMP version 1 *
if i am requesting for any object and am using GetRequest(..)
how it will work if many errors happens in the responce message ?
and how to represent it using error index ?
please remember that error index is used to identify and specify which Variable has the error i.e one error >>
You don't. The error-status and error-index fields should indicate the first variable that was unable to be retrieved due the error indicated by error-status. To determine that any of the remaining variables are also unable to be retrieved, the indicated error needs to be corrected (e.g. variable removed from the request, OID corrected, etc.) and the request re-sent. At that point, the error-status and error-index of the response would indicate the next variable with an error (if any).

Resources