Electron - Uncaught (in promise) Error: An object could not be cloned - promise

I've this error when I click on my button:
Uncaught (in promise) Error: An object could not be cloned.
I start with electron, and I would like to take advantage of this topic to know the difference between invoke and send (I tried both, with the same error)
Main.js
ipcMain.handle('savePdf', (event, pdfFile) => {
console.log(event);
console.log(pdfFile);
return pdfFile;
}
preload.js
contextBridge.exposeInMainWorld('pdf', {
savePdf: (file) => ipcRenderer.invoke('savePdf', file),
})
rendered.js
const pdfFileInput = document.getElementById('input-file'); // OK
const pdfFile = pdfFileInput.files[0]; // OK
console.log(pdfFile); // OK
await pdf.savePdf(pdfFile);

Related

xml2js is not throwing an error when I pass in an invalid xml to parse.parseString

I am trying to write a jest test for the xml2js parse.parseString, but when I pass in an invalid xml it just bypasses the parse.parseString function rather than return the error in the callback function. I want to trigger the error in the callback function.
import xml2js from 'xml2js';
const parser = new xml2js.Parser({
async: false
});
parser.parseString(`<_>&%xstest</_>`, (err, result) => {
if (err) {
console.log('error',err)
throw new Error(`Parser error: ${err}`);
}
console.log('result', result)
});
any idea on why I can not trigger the err in the callback of parse.parseString to call? I am unable to get parse.parseString to throw an error.

How to fix 'TypeError: process.hrtime is not a function' in nativescript?

I am building a nativescript (+Angular) app with aws-amplify. Particular while using the S3 Storage API from aws-amplify, I get following error:
AWSS3Provider - get signed url error TypeError: process.hrtime is not a function. (In 'process.hrtime()', 'process.hrtime' is undefined)
I am using the following polyfills
(window as any).global = window;
(window as any).process = {
env: { DEBUG: undefined },
};
In my code, I check if process is not undefined.
if(typeof process !== 'undefined') {
Storage.get('fileassets/asset.txt')
.then(result => alert(result))
.catch(err => alert(err));
} else {
alert("process is undefined");
}
There is no alert raised, but it seems the native code S3Provider relies on process.hrtime, that can't be resolved in nativescript non{N} environment
I expect that aws-amplify API is successfully executed, as It have no control to hack that to avoid calling process.hrtime.

Apollo Client on React - How to retrieve the error message fomated?

I can't find info about it in anywhere...
Consider this very simple scenario...
<Mutation mutation={LOGIN_MUTATION}>
{(login, { data, loading, error }) => {
if (error) {
console.log(error)
}
I am receiving a string error message like...
Error: GraphQL error: ERROR_INVALID_LOGIN_PROVIDER
at new ApolloError (bundle.umd.js:92)
at MutationData.onMutationCompleted (react-hooks.cjs.js:636)
at react-hooks.cjs.js:559
at tryCallOne (core.js:37)
at core.js:123
at JSTimers.js:289
at _callTimer (JSTimers.js:146)
at _callImmediatesPass (JSTimers.js:194)
at Object.callImmediates (JSTimers.js:458)
at MessageQueue.__callImmediates (MessageQueue.js:366)
I can't take actions based on the error message formated in this way. ERROR_INVALID_LOGIN_PROVIDER could be ERROR_INVALID_PASSWORD, for example...
I need to take decisions based on the error messages. but I just receive a string containing the graphql error, the modules inside the js and a lot of information that's not important. Is there any way to receive the error message formatted imn a way that I can extract only the server error ?
This should be possible
error in your example should be an ApolloError with the possible GraphQLErrors or a NetworkError
(login, { data, loading, error }) => {
if (error) {
if (error.graphQlErrors && error.graphQLErrors.length > 0) {
// There are graphQL errors and there may be multiple but its always an array.
// You should handle it properly
const { message } = error.graphQLErrors[0]
console.log(message) // e.g. ERROR_INVALID_LOGIN_PROVIDER
} else if (error.networkError) {
// There may be a network error
const { message } = error.networkError
console.log(message) // e.g. NetworkError when attempting to fetch resource.
}
}

How to fix 'TypeError: this.isCallback is not a function' error for UserAgentApplication in msal.js

using Msal v1.0.2, loginPopup is not working from iFrame.
trying to get the UserAgentApplication instance using client_id. its throwing an exception:
TypeError: this.isCallback is not a function
at Object.UserAgentApplication (UserAgentApplication.ts:228)
const myMSALObj = Msal.UserAgentApplication(msalConfig);
myMSALObj.loginPopup(["user.read"]).then(function (loginResponse) {
return myMSALObj.acquireTokenSilent(accessTokenRequest);
}).then(function (accessTokenResponse) {
const token = accessTokenResponse.accessToken;
}).catch(function (error) {
//handle error
});
sample from . 'Quickstart for MSAL JS' works fine but when I try to integrate Msal inside iFrame of my JavaScript plugin code, its not working.
working code from sample:
var myMSALObj = new Msal.UserAgentApplication(msalConfig);
myMSALObj.handleRedirectCallback(authRedirectCallBack);
myMSALObj.loginPopup(requestObj).then(function (loginResponse) {
acquireTokenPopupAndCallMSGraph();
}).catch(function (error) {
//Please check the console for errors
console.log(error);
});
there was a typo causing this exception: TypeError: this.isCallback is not a function at Object.UserAgentApplication (UserAgentApplication.ts:228)
fix: const myMSALObj = new Msal.UserAgentApplication(msalConfig);
That should solve this exception issue.

Axios catch will not trigger

I have a react app that the user will enter info into a redux form and the function is called. I have a axios post that will not catch an error. I'm not sure what this is happening.
export function vehicleformsubmit(props){
const input={
rfidtag: rfidtag.value,
vin: vin.value,
vehzone: vehzone.value
};
var request=axios.post(`http://localhost:9000/api/bmwvehicle/create`, input);
return function(dispatch){
request.then((response) =>{
dispatch(createVehicleSuccess(response.data, response.status));
}).catch((error) =>{
if(error.response){
dispatch(vehicleHaveError(true));
}
});
};
}
This is that I get back:
createError.js:16 Uncaught (in promise) Error: Request failed with
status code 500
at createError (createError.js:16)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:77)

Resources