How do you catch NEAR json RPC Errors - nearprotocol

I'm creating accounts using the json rpc for NEAR but when things fail, there isn't really an error that is passed back, so I'm unable to catch anything.
The object with key status is a test, this is returned after the function call has finished, but if there are no errors to catch, I can't tell if anything failed.
How are you catching errors here.
Receipts: 4epNvrYNDK2u4p7K4RKMqbqmoV6WMKjCFtE926uiTQEu, HMnN8FXcJVT4PjQxi5RAmBLLRn2gNaZwgDkNKXX66jj5
Failure [myaccount.mintspace2.testnet]: Error: {"index":0,"kind":{"ExecutionError":"Smart contract panicked: panicked at 'Failed to deserialize input from JSON.: Error(\"missing field `receiver_id`\", line: 1, column: 79)', store/src/core.rs:41:1"}}
{
status: 'success',
}

Related

Can Cypress give me an error message when there has been an error?

I have the below snippet from my test case:
cy.get('item_here').should('not.exist');
Can cypress give me a custom error message when the "item_here" does exist?
Thanks,
You can chain a log message on to the existing code, and it will only run if the element does not exist.
cy.get('item_here').should('not.exist')
.then(() => cy.log('no such element found')) // Note; this is an additional log
Changing both "success" and "fail" messages is hard because Cypress likes to show the red AssertionError block when anything fails or an error is thrown.
You can use the should() callback version, but please use an expect() inside otherwise you do not have retry,
cy.get('item_here').should($el => {
expect($el, 'Cannot be found').to.not.exist // expect causes retry for 4 seconds
Cypress.log({
name: 'Missing',
message: 'Cannot be found'
})
})
You can throw your own errors in a callback function for .should().
cy.get(".does-not-exist")
.should("not.exist")
.then(($el) => {
if ($el == null) {
throw new Error("Item does not exist in DOM");
}
});

Cannot log stack traces with apollo server

I'm building a graphql application with apollo server and I'm having trouble figuring out how to log stack traces serverside in production mode.
I found these docs but it's not clear how to correctly log stack traces in production.
I have the following formatError function:
formatError: ((err) => {
console.error(err.originalError)
return err
})
and when one of my resolvers throws an error with NODE_ENV=production I see the following output:
Error: Unexpected error value: "could not get config value"
at locatedError (/tripvector/node_modules/graphql/error/locatedError.js:24:9)
at /tripvector/node_modules/graphql/execution/execute.js:491:54
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async execute (/tripvector/node_modules/apollo-server-core/dist/requestPipeline.js:204:20)
at async processGraphQLRequest (/tripvector/node_modules/apollo-server-core/dist/requestPipeline.js:138:28)
at async processHTTPRequest (/tripvector/node_modules/apollo-server-core/dist/runHttpQuery.js:187:30)
However, when I run in debug mode, the original error is printed as I expect:
Error: could not get config value
at validate (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/lib/settings/settings.js:11:15)
at getGoogleSecret (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/lib/settings/settings.js:29:12)
at Object.loginWithGoogle (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/api/users/graphql/mutations.js:141:30)
at field.resolve (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/apollo-server-core/dist/utils/schemaInstrumentation.js:52:26)
at executeField (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:469:20)
at /Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:365:22
at promiseReduce (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/jsutils/promiseReduce.js:23:9)
at executeFieldsSerially (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:361:43)
at executeOperation (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:335:14)
at execute (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:130:20)
I throw the error with the following code:
function validate(val) {
if (!val) {
throw new Error('could not get config value')
}
return val
}
How can I correctly configure apollo server to print stack traces for errors, even in production?
As usual, I found the answer 2 minutes after asking. I was doing some silly error catching and rethrowing in promises which is why this problem was happening only in production.

nightwatchjs saveScreenshot giving TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView

I am working on an automation prototype using Nightwatch js and when I am trying to save screenshot, it is giving below error
Error while running .getScreenshot() protocol action: An unknown
server-side error occurred while processing the command. – An unknown
server-side error occurred while proces...
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed
(10.032s)
TypeError: The "data" argument must be of type string or an instance
of Buffer, TypedArray, or DataView. Received an instance of Object
at Object.writeFile (fs.js:1487:5)
at FSReqCallback.oncomplete (fs.js:180:23)
FAILED: 1 errors and 1 passed (9.662s)
relevant data for nightwatch.config.js:
test_settings: {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
test file data:
.pause(3000).saveScreenshot('./screnshots/test.png');
Nightwatch version: "1.5.1"
please note that due to office policy cannot paste complete testcase data here.

xcode treating catching an error as a test failure

I've written the following function:
func sendMessage(message:Dictionary<String,AnyObject>) {
do {
let json = try NSJSONSerialization.dataWithJSONObject(message, options: [])
let jsonStr = NSString(data: json, encoding: NSUTF8StringEncoding)
self.wsSource.writeString(jsonStr as! String)
} catch let err as NSError {
Rc2LogError ("error sending json message on websocket:\(err)")
}
}
Here is a unit test that should pass:
func testSendMessageFailure() {
let dict = ["foo":wspace!, "bar":22]
session!.sendMessage(dict)
XCTAssertNil(wsSrc.lastStringWritten)
}
But the test fails with the message:
test failure: -[Rc2SessionTests testSendMessageFailure()] failed: failed: caught "NSInvalidArgumentException", "Invalid type in JSON write (Rc2.Rc2Workspace)"
That isn't a failure. It is what I expect! Does this mean it is impossible to write a unit test that calls a function that has an error handler that handles the error?
How can I tell XCTest/Xcode that a caught error/exception does not mean a test failed?
do-catch statements are only for catching error thrown by the function. They do not catch exceptions. Exceptions are used to show that there is a programming error.
If obj will not produce valid JSON, an exception is thrown. This exception is thrown prior to parsing and represents a programming error, not an internal error. You should check whether the input will produce valid JSON before calling this method by using isValidJSONObject:.
Source: NSJSONSerialization
What is happening is that message is not an object that can be represented in json. My guess would be that wspace contains a type that can not be converted to json.

Handling errors using Parse.com Cloud Code and javascript API

What is the best way to handle errors using Parse.com Cloud Code. I'm able to use console.log and Firebug to see when Parse Cloud Code throws an error, but I need some help with how to notify the client that something went wrong. Some sample code from both sides would really be great -- Cloud Code and client side javascript code.
I preferred it this way -
On Cloud Code make one ErrorHandler.JS file -
exports.sendError = function(response, message, data) {
console.log("Message - " + message + " Data - " + JSON.stringify(data)); // To print LOG on Cloud Code
// Moreover you can use any of - "console.error/warn" - as mentioned - https://parse.com/docs/cloud_code_guide#logging
response.error({
status : false, // Indicates EXECUTION STATUS - I am using "successHandler" also & using STATUS as "true"
message : message, // Refers to Error Message
data : data || {} // Error Object or your customized Object
});
}
& client side you will have all data to print if you want or you can just show alert message to the Users.
More over it's preferred to check both SERVER side as well as CLIENT side LOG for DEVELOPING purpose because PARSE Cloud Code stores only last 100 messages in LOG.
& In order to implement proper LOGGING you must made some custom procedures with proper storage structure in terms of CLASS.
Parse has a section on Error Handling for Promises.
For instance when running a query in Cloud Code
query.find().then(function(result){ ... },
function(error){
response.error("Error occurred: " + error.message);
}
That will send error message down the client.
As an experiment I tried response.error with various strings/objects, below is what each returned (the commment shows the return value to the client).
Essentially, it always returns code 141, and you can only return a string. I was surprised that passing the proverbial err object from an exception returned {} my guess is this is for security reasons. What I do not understand is why you can't console.log(err) on the server as this has caused me a lot of confusion when trying to figure out what is going on. You basically always need to do err.message in your console.log statements to figure out what's really going on.
response.error("Some String of text") // --> {code: 141, message: "Some String of text"}
response.error( new Error("My Msg") ) // --> {code: 141, message: "{}"}
try {
var x = asdf.blah;
}catch(err) {
return response.error(err.message); // --> {code: 141, message: "asdf is not defined"}
}
response.error( err ); // --> {code: 141, message: "{}"}
response.error( Parse.Error(Parse.Error.VALIDATION_ERROR, "My Text") ); // --> {code: 141, message: "An error has occurred"}

Resources